How do prompt user to repeat the program or finish using it

Hello im quite new to c++ and havent really got a strong knowledge of it as i am just picking it up . i am loooking to make this program prompt the user with " do you want to do it again ? Y/N " if Y it starts the program again and takes it back to the main menu , if N it will just end the program , ive fiddled around with the code but i cant seem to make it work , anyone be able to help ,




cin.ignore();


}


Last edited on
1
2
3
4
5
6
char choice;
do{
   //...
   cout<<"do you want to do it again ? Y/N ";
   cin>>choice;
}while(choice=='Y');
cheers but i dont know where to put it , ive had a fiddle but cant seem to get it in the right place , it just repeats that bit of code where as im after getting it to repeat the whole thing ,
ne555 meant for you to put what you want repeated where he indicated with //... .


You main should look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main () 
{ char choice;
   //  loop until user doesn't want to continue
   do
   { // loop until the menu is processed 
      while (! processMenu()) 
      { // if we get here, the menu was not processed correctly 
         // so we bother them some more 
         cout << "Sorry, that is not a valid choice." << endl; 
         cout << "Please try again." << endl << endl << endl; 
       }  // end of  process menu loop
       // menu has been processed successfully 
       cout << "Calculate more grades ? y/n .\n" << endl; 
       cin>>choice;
   } while(choice=='Y');
}


PLEASE USE CODE TAGS (the <> formatting button) when posting code.



Last edited on
Thank you both so much , youve saved my life , much love xx
Topic archived. No new replies allowed.