I don't know how to create a loop to repeat and quit the program

I have to use do-loop to prompt the user either to repeat or to quit the program. I started the program with declaring the variable as character and i don't know if it's right or not.


char quit = q


do {
// prompt the user if he/she wants to play again
cout << "Enter q to quit the program" ;
cin >> quit;

}


whatelse should I add to this?
Put

1
2
3
if(quit == "q" || quit == "Q"){
return 0;
}
Last edited on
what about repeating the program?
Use a while loop. So do:

1
2
3
4
5
6

while(quit != "q") {
 // prompt the user if he/she wants to play again
 cout << "Enter q to quit the program" << endl;
 cin >> quit;
}


If you use this you do not need the if statement i provided earlier.
Last edited on
then will it automatically repeat the program unless I enter 'q'?
Yes, it will keep asking you to enter q, then when you do it will quit. You can also just enter random crap and press enter and it will still keep running until q is entered.
Last edited on
Alright, thank you so much!! =)
Your welcome :D
Topic archived. No new replies allowed.