Completed code, can't figure out loop for Y/N continue or quit

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

void ShowProgramHeader();
void printInstructions();
void Intro();
int totalValue();

int main()

{
string name;
int totalValue=0;
int playerScore=0, compScore=0;
int getUserGuess, getComputerGuess;
int option;
int choice;


while(1)
{


//Intro to the game and rules
cout <<"Welcome to Rock, Paper, Scissors, Lizard, and Spock! " << endl;
cout <<" " << endl;
cout <<"Rules of the game are as follows: " << endl;
cout <<" " << endl;
cout <<"Scissors cuts Paper, Paper covers Rock, Rock crushes Lizard, Lizard poisons Spock" << endl;
cout <<"Spock smashes Scissors, Scissors decapitates Lizard, Lizard eats Paper, Paper disproves Spock" << endl;
cout <<"Spock vaporizes Rock, and Rock crushes Scissors. " << endl;
cout <<" " << endl;

//Lets the user know game is starting
cout <<"Let the games begin!!!" << endl;
cout <<" " << endl;

//Prompt for username which is used throughout game
cout <<"Please enter your name here: ";
getline(cin,name);

//Game begins
cout <<"Please select a choice of (1-5):" << endl;
cout <<"1 = Rock 2 = Paper 3 = Scissors 4 = Lizard 5 = Spock " << endl;
cout <<"Enter your choice here: ";
cin >> getUserGuess;


if ( getUserGuess == 1 )
{
cout <<"You have chosen: Rock" << endl;
}

else if ( getUserGuess == 2 )
{
cout <<"you have chosen: Paper" << endl;
}

else if ( getUserGuess == 3 )
{
cout <<"You have chosen: Scissors" << endl;
}

else if ( getUserGuess == 4 )
{
cout << "You have chosen: Lizard" << endl;
}

else if ( getUserGuess == 5 )
{
cout << "You have chosen: Spock" << endl;
}

srand(time(0));
getComputerGuess = rand() % 5 + 1;

if ( getComputerGuess == 1 )
{
getComputerGuess = 1;
cout << "The computer has chosen: Rock" << endl;
}

else if ( getComputerGuess == 2 )
{
getComputerGuess = 2;
cout << "The computer has chosen: Paper" << endl;
}

else if ( getComputerGuess == 3 )
{
getComputerGuess = 3;
cout << "The computer has chosen: Scissors" << endl;
}

else if ( getComputerGuess == 4 )
{
getComputerGuess = 4;
cout << "The computer has chosen: Lizard" << endl;
}

else if ( getComputerGuess == 5 )
{
getComputerGuess = 5;
cout << "The computer has chosen: Spock" << endl;
}

if ( ( getUserGuess == 1 && getComputerGuess == 1 )||
( getUserGuess == 2 && getComputerGuess == 2 ) ||
( getUserGuess == 3 && getComputerGuess == 3 ) ||
( getUserGuess == 4 && getComputerGuess == 4 ) ||
( getUserGuess == 5 && getComputerGuess == 5 ) )

{
{
cout << "You both have chosen wisely, it's a TIE!" << endl;

//Keeps score of wins and losses
playerScore=playerScore+totalValue;
compScore=compScore+totalValue;
cout << name << ", your score is: "<<playerScore<<endl;
cout <<"Computers score is: "<<compScore<<endl;
cin.get();


cout << "Would you like to play again? (Y/N) ";
cin >> option;

if (option == 'n' || option == 'N');

cout <<"Thanks for playing! Come back soon!!!" << endl;
cout <<" " << endl;
cout <<"Your total score was: "<<playerScore+totalValue << endl;
cout <<"Computers total score was: "<<compScore+totalValue << endl;

if (playerScore+totalValue > compScore+totalValue)
cout << "You are the winner!" << endl;
else if (playerScore+totalValue < compScore+totalValue)
cout << "The computer has won!" << endl;
else cout <<"It's a tie." << endl;
break;
}

}


else if (( getUserGuess == 3 && getComputerGuess == 2 ) ||
( getUserGuess == 2 && getComputerGuess == 1 ) ||
( getUserGuess == 1 && getComputerGuess == 4 ) ||
( getUserGuess == 4 && getComputerGuess == 5 ) ||
( getUserGuess == 5 && getComputerGuess == 3 ) ||
( getUserGuess == 3 && getComputerGuess == 4 ) ||
( getUserGuess == 4 && getComputerGuess == 2 ) ||
( getUserGuess == 2 && getComputerGuess == 5 ) ||
( getUserGuess == 5 && getComputerGuess == 1 ) ||
( getUserGuess == 1 && getComputerGuess == 3 ))
{
{
playerScore++;
cout << "Congratulations " << name << " you are the WINNER!" << endl;

//Keeps score of wins and losses
playerScore==playerScore+totalValue;
compScore==compScore+totalValue;
cout << name << ", your score is: "<<playerScore+totalValue<<endl;
cout <<"Computers score is: "<<compScore+totalValue<<endl;

cout << "Would you like to play again? (Y/N) ";
cin >> option;

if (option == 'n' || option == 'N');

cout <<"Thanks for playing! Come back soon!!!" << endl;
cout <<" " << endl;
cout <<"Your total score was: "<<playerScore+totalValue << endl;
cout <<"Computers total score was: "<<compScore+totalValue << endl;

if (playerScore+totalValue > compScore+totalValue)
cout << "You are the winner!" << endl;
else if (playerScore+totalValue < compScore+totalValue)
cout << "The computer has won!" << endl;

else cout <<"It's a tie." << endl;
break;
}
}



else if (( getUserGuess == 2 && getComputerGuess == 3 ) ||
( getUserGuess == 1 && getComputerGuess == 2 ) ||
( getUserGuess == 4 && getComputerGuess == 1 ) ||
( getUserGuess == 5 && getComputerGuess == 4 ) ||
( getUserGuess == 3 && getComputerGuess == 5 ) ||
( getUserGuess == 4 && getComputerGuess == 3 ) ||
( getUserGuess == 2 && getComputerGuess == 4 ) ||
( getUserGuess == 5 && getComputerGuess == 2 ) ||
( getUserGuess == 1 && getComputerGuess == 5 ) ||
( getUserGuess == 3 && getComputerGuess == 1 ))

{
cout << "I'm sorry " << name << ", but you have LOST, try again!" << endl;
compScore++;
}

{
//Keeps score of wins and losses
playerScore=playerScore+totalValue;
compScore=compScore+totalValue;
cout << name << ", your score is: "<<playerScore+totalValue << endl;
cout <<"Computers score is: "<<compScore+totalValue << endl;

cout << "Would you like to play again? (Y/N) ";
cin >> option;

if (option == 'n' || option == 'N');
cout <<"Thanks for playing! Come back soon!!!" << endl;
cout <<" " << endl;
cout <<"Your total score was: "<<playerScore+totalValue << endl;
cout <<"Computers total score was: "<<compScore+totalValue << endl;
}

{
if (playerScore+totalValue > compScore+totalValue)
cout << "You are the winner!" << endl;

else if (playerScore+totalValue < compScore+totalValue)
cout << "The computer has won!" << endl;

else cout <<"It's a tie." << endl;
break;
}

}
return 0;
}
Last edited on
if (option == 'n' || option == 'N');
remove the semicolon, and put a bracket so that all statements that should be executed if the user choose 'n' or 'N' will be executed
Topic archived. No new replies allowed.