Page 1 of 1

C++ Question....thanks for any help you can give

Posted: Mon Apr 07, 2003 11:00 pm
by J
I only took 1 C++ class and am trying to remember how to write code to reloop my code. I wrote a program that asks the user to answer 5 questions, and it tells them which weather model to use based on the answers they submit. But I don't remember how to make code so that I can ask at the end if they want to test another time. Basically I have an output statement asking "Would you like to test another model (Y=Yes, N=No)" but I don't know the code to actually go through the code again. Thanks for the help

RE:C++ Question....thanks for any help you can give

Posted: Mon Apr 07, 2003 11:00 pm
by Khumba
char c;
do {
   ... code ...
   printf("Again (Y/N)? ");
   scanf("%c", c);
} while (c != 'y' && c != 'Y');

RE:C++ Question....thanks for any help you can give

Posted: Tue Apr 08, 2003 11:00 pm
by Anton
You probably ment:

char c;
do {
   ... code ...
   printf("Again (Y/N)? ");
   scanf("%c", &c);//!!!!!!! &c not c
} while (c != 'y' && c != 'Y');

Anton.