Dev C++ Yes Or No Question

  

P: 8
Hi, i have a bit of a problem here.
I have an assignment to do an animal guessing game using an original database and updating it as the user enters new animals in it. The program enters the file data into an array of structures, with the animal and question in the same variable(question) and the bool isAnimal tells me whether its an animal or a question. If its a question it is followed by two numbers; one for the position of the line to go to if the user enters 'no' and another for 'yes'. The program works fine until the user inputs 'no' for a new animal(updated animal) after he enters yes for a new question(that he entered the last time to differentiate between animals). Here is the code, and sorry if the variable names are bad. Im using windows xp and visual c++ 2005.
  1. *snipped by Moderator*
  2. if(answer1 'yes')
  3. cout<<' I WIN!!!'<<endl << endl;
  4. else
  5. if(answer1 'no')
  6. {
  7. cout << ' I give up, what were you thinking of?' <<endl;
  8. cin >> game[x].question;
  9. game[x].isAnimal = true;
  10. x++;
  11. cout<< 'Please type a question that has a yes answer for '<< game[x - 1].question
  12. << endl << ' and a no answer for ' << game[game[c].no].question << ' (without a question mark):' << endl;
  13. cin.ignore();
  14. getline(cin, game[x].question);
  15. game[x].isAnimal = false;
  16. game[x].no = game[c].no;
  17. game[x].yes = x - 1 ;
  18. game[c].no = x;
  19. x++;
  20. }
  21. *snipped by Moderator*

Adak - The Yes No at the start is to ask and check whether there is any customer at that time. Thank you Adak for helping me out! This is the latest code i've been working on. Everything looks ok, but if the user enter name that have 2 or more such as - Jackie Chan or Edward Scissor Hands, the Weight per KG will be skip.

So I'm looking to create a function that prompts the user to enter 'Y' for 'Yes restart the program' and 'N' for No, do not restart.

I know this should use the boolean operator, I'm just unsure as to how to implement it.

I also know to encase the body in a while loop ending in 'else if ('no')' for example.

Question

I know this is completely wrong, but it's what I'm thinking could work:

and the while loop being something like:

Thanks a lot for all the help!

  • 4 Contributors
  • forum 6 Replies
  • 2,912 Views
  • 20 Hours Discussion Span
  • commentLatest Postby SyrneLatest Post

Dev C Yes Or No Question Mark

Recommended Answers

C++ Yes Or No

Your trying to compare letters, not numbers.
[CODE]int select;//should be char or string[/CODE]

Dev c yes or no question game

[CODE]if(select.equals('Y'))
{//return a value}
if(no)
{//return a value}[/CODE]

ProgramJump to Post

Dev C++ Yes Or No Questions

All 6 Replies