Write a function bool yes( ) which reads a string from the keyboard and returns
ID: 2990111 • Letter: W
Question
Write a function bool yes( ) which reads a string from the keyboard and returns true if the string begins with 'Y' or 'y'; otherwise it returns false. Now write a main to play a simplified version of "Twenty Questions" which asks only three yes/no questions and calls yes( ) to get the user's answers and deduce which of eight items matches. A sample run should look like this:
Are you thinking of something that is alive? No
Are you thinking of a Sesame Street character? Yup
Are you thinking of something that is green? yessiree
Explanation / Answer
bool yes(){
char arr[5];
int i;
for (i=1;i<5;i++){
cin>> arr[i];
}
if(arr[0] == 'y' || arr[0]=='Y'){
return true;
}else{
return false;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.