Do You Wish to Continue in C
Press 1 to continue and 2 to quit
I'm learning C++ at school.
But i'm trying to make some own fun stuff, and i want to include
Press1 to continue
Press 2 to quit
But i don't really have an idea.
cout << endl << "Do you want to continue? (Yes/No)" << endl;
cin >> chyesno;
while (chyesno == 'No')
{
cout << endl << "U have chosen to quit the program!" << endl << endl;
break; (what do i need to put here? Break;)
}
I would make a smaller loop inside a large loop body to check for valid choices.
Then exit the appropriate loop on one of the options.
| |
Replace break with return 0;
Edit: I would prefer something like this:
| |
It would be easily modifiable if you insist on using numbers.
Last edited on
I tried to do this, but if i chose 2 it doesnt quit the whole program.
return 0; aint working because i used void main() at start
still, many thanks :D
EDIT:
std::cout << "Enter 1 to continue" << std::endl;
std::cout << "Enter 2 to quit" << std::endl;
std::cout << "Your choice? "; std::cin >> choice;
If I press 1 this keeps coming?
Last edited on
Well I only gave you a snippet. If you still see it, its continuing the main loop then hits the mini loop again. Add some text above like a std::cout << "Main Loop" << std::endl;
You should be repeating the main loop everytime you press 1, and then it will ask if you want to do it again once the main loop is completed.
But i mean, when you press 1 --> it will make the triangle it is supposed to make. (not to continue the loop)
and when you press 2 --> is just stops the program
@ browni, thats not really working with my script :(
is that what quit means? To end the program?
I tought that quit was stopping the program
rometotalw wrote: |
---|
because i used void main() at start |
That's non standard. Never use void main(). You should probably ditch whatever tutorial you're using, because if it's using void main() who knows what other bad/non standard practices it's teaching you as well.
You have the loop as the body of the program right?
If this is how it looks, when you enter 2, it will end the program. I tested it. Works.
| |
If you want i can PM you my code. (it's in dutch) but maybe you can see what's wrong?
and where you typ "do not code here unless you only want to see this when the program closes"
I must code there something.
EDIT: i changed it a little, now it works. I removed the loop because whenever i typ 1 it will continue BUT it will also start all over again.
Last edited on
Topic archived. No new replies allowed.
Source: https://cplusplus.com/forum/beginner/34810/
0 Response to "Do You Wish to Continue in C"
Post a Comment