How to add the play again option?

So , i had to make an rock paper scissors game . After lot of hard work and struggle ,I completed it but my professor rejected it since I didnot add option where it says "Would you like to play again .Y/N " . I have tried everything for hours and hours but cant figure out as the code has too many brackets ! Any help would be appreciated. THank you. . Here is my code


#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

// for displaying the outputs to the user; passing string to functions
void user_win()
{
cout << "\n Congratulations! You beat computer.\n" << endl << endl;

}

void user_lose()
{
cout << "\n Computer wins ! You Lose.\n " << endl << endl;
}

void user_draw()
{
cout << " \nIts a draw ! Unbelieveable.Please play again\n " << endl;

}

int main()
{

{

srand(time(NULL)); // for generating random the time is unsigned
int user_choice;
int comp_choice;

// Displaying the title and getting the user choice

cout << "\n ****~~ Rock , Paper , Scissors Game ~~**** \n ";
cout << " Good luck\n\n ";
cout << "Please enter 1 for rock , 2 for paper and 3 for scissors:";
cin >> user_choice;

comp_choice = (rand() % 3) + 1; //equation for generating random number

//for conforming user what he choosed

if (user_choice == 1)
{
cout << "\nYou choosed Rock " << endl;
}
else if (user_choice == 2)
cout << "\nYou choosed Paper " << endl;

else if (user_choice == 3)
{
cout << "\nYou choosed Scissors " << endl;
}
else
{ // Input Validation
cout << "\nInvalid entry ! Please enter 1 for rock, 2 for paper and 3 for scissors:";
cin >> user_choice;
}

// Now if else statements for computer selections

if (comp_choice == 1)
{
cout << "Computer choosed Rock! " << endl;
}
else if (comp_choice == 2)
{
cout << "Computer choosed paper!" << endl;
}
else if (comp_choice == 3)
{
cout << "Computer choosed scissors! " << endl;
}

// all conditions for deciding who wins the game using nested if else

// for draw

if (user_choice == comp_choice)
{
user_draw();

}


// for win combination

if (user_choice == 1)
{
if (comp_choice = 2)
{
user_lose();

}
else if (comp_choice = 3)
{
user_win();

}
}
// for lose combination

else if (user_choice == 2)
{
if (comp_choice == 1)
{
user_win();

}
else if (comp_choice == 3)
{
user_lose();

}
}

//for lose

else if (user_choice == 3)
{
if (comp_choice == 1)
{
user_lose();

}
// for win

else if (comp_choice == 2)
{
user_win();

}
}
I see you tried to use code tags, but you put the code after them instead of between them:
http://www.cplusplus.com/articles/jEywvCM9/

Try wrapping your game inside a while loop that breaks if they choose not to play again, but keeps looping if they do choose to play again.
Topic archived. No new replies allowed.