182k views
3 votes
Given a int variable named yesCount and another int variable named noCount and a char variable named response, write the necessary code to read a value into response and then carry out the following: if the character typed in is a y or a Y then increment yesCount and print out "YES WAS RECORDED" if the character typed in is an n or an N then increment noCount and print out "NO WAS RECORDED" If the input is invalid just print the message "INVALID" and do nothing else.

1 Answer

5 votes

// reading the value in response variable

cout<<"Enter the value :";

cin>>response;

// checking the value and printing the results

if(response == 'y' || response == 'Y')

{

yesCount+=1;

cout<<"YES WAS RECORDED";

}else if(response == 'n' || response == 'N')

{

noCount+=1;

cout<<"NO WAS RECORDED";

}else

cout<<INVALID";

User Sambath Prum
by
5.3k points