cant figure out how to stop my do while.

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int choice;
int compchoice = (rand()%2)+1;
cout << " *---------------------*" << endl;
cout << " | **** O O ==== |" << endl;
cout << " |****** \\/ | | |" << endl;
cout << " |****** /\\ | | |" << endl;
cout << " | **** / \\ ==== |" << endl;
cout << " *---------------------*" << endl;

cout << "****************************************************\n";
cout << "| |\n";
cout << "| Welcome to Rock Paper Scissors! |\n";
cout << "| You are playing against the computer. |\n";
cout << "| Type 0 for rock, 1 for paper, and 2 for scissors |\n";
cout << "| |\n";
cout << "****************************************************\n";
cin >> choice;

if (choice == 0)
{
if (compchoice == 0)
cout << "It's a tie!\n\n\n\n";
else if (compchoice == 1)
cout << "Paper beats rock! Sorry, you lose!\n\n\n\n";
else if (compchoice == 2)
cout << "Rock beats scissors! You win!\n\n\n\n";
}

if (choice == 1)
{
if (compchoice == 0)
cout << "It's a tie!\n\n\n\n";
else if (compchoice == 1)
cout << "Paper beats rock! You win!\n\n\n\n";
else if (compchoice == 2)
cout << "Scissors beat paper! Sorry, you lose!\n\n\n\n";
}

if (choice == 2)
{
if (compchoice == 0)
cout << "It's a tie!\n\n\n\n";
else if (compchoice == 1)
cout << "Scissors beat paper! You win!\n\n\n\n";
else if (compchoice == 2)
cout << "Rock beats scissors! Sorry, you lose!\n\n\n\n";
}
char again;
do
{
cout << "That was a good game! \nWould you like to play again?";
cin >> again;
} while (again == 'Y');

return main();
Your loop is only applied to the cout/cin statement. Move the "char again; do {" up to where you want to repeat everything. Currently, you can terminate the loop by typing anything except capital Y.
Last edited on
i want the menu and all to repeat basically game start from the begining y to play again n to exit im pretty new to c++ and im not really getting hwhere to move it too
Well just look at the syntax of the loop:
1
2
3
4
5
6
do // This says to do something
{ // This is the starting brace. Do everything in here
   // .. Do stuff
} // This is the ending brace. Do everything up until this point
while (condition); // Condition to check each time.
// If it's true, it does everything in the braces again 


So whatever you want to repeat each time should go between the { and }. This will ensure that every time that loop runs, so will that code.
works thanks very much had a sub in this unit and he didnt teach us anything just played on face book...
Topic archived. No new replies allowed.