Rock Paper Scissors Lizard Spock program help

Need to write a rock, paper, scizzors program with following retraints: Make sure to have one function displaying the menu (scissors, paper, or rock), reading the choice, validating it and rereading if needed, and then returning the valid choice as a number 1-3.
Make sure to have another function to which you send what the user selected and what computer generated, and the function will declare the winner printing the result.
Make sure to use srand()
Also for extra 10% you may put a loop for the program to keep working on multiple games until the user enters a quit choice on the menu (the same menu where the choice is entered).

I know theres prolly an easier way to write program using cases, but i was having issues with it, so rewrote it using if/ elseif statements and it runs. Just Im having issue with inserting a loop so that it will just run program over and over until user imputs quit.

#include <iostream>
#include <ctime>
#include <vector>
#include<random>
#include<cstdlib>

using namespace std;

int main()
{

//variable to hold players choice
int PlayerChoice;


// Intro to game

cout << "Would you like to play a game...." << endl;

cout << "Choose Your weapon of choice: " << endl;
cout << "1. Scissor " ;
cout << " 2. Rock " << endl;
cout << "3. Paper ";
cout << " 4. Lizard " << endl;
cout << "5. Spock ";
cout << " 6. Quit " <<endl;

//Obtain users choice
cin >> PlayerChoice;


//variable to hold computers choice

int aI;



srand(time(0));

//To hold the random number
aI = rand() % 5 + 1;


//Computer choosing random number
if (aI == 1)
{
aI = 1;


}

else if (aI == 2)
{
aI = 2;


}

else if (aI == 3)
{
aI = 3;


}

else if (aI == 4)
{
aI = 4;


}
else if (aI == 5)
{
aI = 5;

}

// Obtain players Choice
if (PlayerChoice == 1)
{

}

else if (PlayerChoice == 2)
{

}

else if (PlayerChoice == 3)
{

}

else if (PlayerChoice == 4)
{

}

else if (PlayerChoice == 5)
{

}

//Comparing the choices to determine outcome

if (PlayerChoice == 1 && aI == 1)
{
cout << "The Computer chose Scissors \n";
cout << "You chose Scissors too\n";
cout << "It's a TIE!" << endl;

}

else if (PlayerChoice == 2 && aI == 2)
{
cout << "The Computer chose Rock\n";
cout << "You chose Rock too\n";
cout << "It's a TIE!" << endl;

}

else if (PlayerChoice == 3 && aI == 3)
{
cout << "The Computer chose Paper\n";
cout << "You chose Paper too\n";
cout << "-It's a Tie!" << endl;

}

else if (PlayerChoice == 4 && aI == 4)
{
cout << "The Computer chose Lizard\n";
cout << "You chose Lizard too\n";
cout << "-It's a TIE!" << endl;

}

else if (PlayerChoice == 5 && aI == 5)
{

cout << "The Computer chose Spock\n";
cout << "You chose Spock too\n";
cout << "It's a TIE! " << endl;

}

else if (PlayerChoice == 3 && aI == 2)
{
cout << "The Computer chose Rock\n";
cout << "You chose Paper\n";
cout << "Paper wil cover the Rock\n";
cout << "SO You WIN!" << endl;

}

else if (PlayerChoice == 2 && aI == 1)
{
cout << "The Computer Chose Scissors\n";
cout << "You Chose Rock\n";
cout << "Rock Crushes Scissors\n";
cout << "So You WIN!";

}

else if (PlayerChoice == 1 && aI == 4)
{
cout << "The Computer chose Lizard\n";
cout << "You chose Scissors\n";
cout << "Scissors Beheads the Lizard\n";
cout << "So You WIN!" << endl;

}

else if (PlayerChoice == 4 && aI == 5)
{
cout << "The Computer Chose Spock\n";
cout << "You Chose Lizard\n";
cout << "The Lizard poisons Spock\n";
cout << "SO You WIN!" << endl;

}

else if (PlayerChoice == 3 && aI == 5)
{
cout << "The Computer Chose Spock\n";
cout << "You Chose Paper\n";
cout << "The paper Disapproves Spocks Logic\n";
cout << "So You WIN!" << endl;


}

else if (PlayerChoice == 4 && aI == 3)
{
cout << "The Computer Chose Paper\n";
cout << "You Chose Lizard\n";
cout << "Lizard eats he Paper\n";
cout << "So You WIN!" << endl;

}

else if (PlayerChoice == 2 && aI == 4)
{
cout << "The Computer Chose Lizard\n";
cout << "You Chose Rock\n";
cout << "The Rock Crushes the Poor Lizard\n";
cout << "So You WIN!" << endl;

}

else if (PlayerChoice == 5 && aI == 2)
{
cout << "The Computer Chose Rock\n";
cout << "You Chose Spock\n";
cout << "Spock just Vaporizes the Rock\n";
cout << "So You Win!" << endl;

}

else if (PlayerChoice == 5 && aI == 1)
{
cout << "The Computer Chose Scissors\n";
cout << "You chose Spock\n";
cout << "Spock Dismantles the Scissors\n";
cout << "So You WIN!" << endl;

}

else if (PlayerChoice == 1 && aI == 3)
{
cout << "The Computer Chose Paper\n";
cout << "You Chose Scissors\n";
cout << "Scissors cuts the Paper\n";
cout << "So You WIN!" << endl;

}

else if (PlayerChoice == 2 && aI == 3)
{
cout << "The Computer Chose Paper\n";
cout << "You Chose Rock\n";
cout << "Paper covers Rock\n";
cout << "You Lose, You get Nothing...Good Day Sir.." << endl;

}

else if (PlayerChoice == 1 && aI == 2)
{
cout << "The Computer Chose Rock\n";
cout << "You Chose Scissors\n";
cout << "Rock Crushes Scissors\n";
cout << "You Lose, You get Nothing...Good Day Sir.." << endl;

}

else if (PlayerChoice == 4 && aI == 1)
{
cout << "The Computer Chose Scissors\n";
cout << "You Chose Lizard\n";
cout << "Scissors Behead the poor Lizard\n";
cout << "You Lose, You get Nothing...Good Day Sir.." << endl;

}

else if (PlayerChoice == 5 && aI == 4)
{
cout << "The Computer Chose Lizard\n";
cout << "You Chose Spock\n";
cout << "The Lizard poisons Spock\n";
cout << "You Lose, You get Nothing...Good Day Sir.." << endl;

}

else if (PlayerChoice == 5 && aI == 3)
{
cout << "The Computer Chose Paper\n";
cout << "You Chose Spock\n";
cout << "Paper Disapproves Spocks Logic\n";
cout << "You Lose, You get Nothing...Good Day Sir.." << endl;

}

else if (PlayerChoice == 3 && aI == 4)
{
cout << "The Computer Chose Lizard\n";
cout << "You Chose Paper\n";
cout << "The Lizard eats the Paper\n";
cout << "You Lose, You get Nothing...Good Day Sir.." << endl;

}

else if (PlayerChoice == 4 && aI == 2)
{
cout << "The Computer Chose Rock\n";
cout << "You Chose Lizard\n";
cout << "The Rock crushes the Lizard\n";
cout << "You Lose, You get Nothing...Good Day Sir.." << endl;

}

else if (PlayerChoice == 2 && aI == 5)
{
cout << "The Computer Chose Spock\n";
cout << "You Chose Rock\n";
cout << "Spock just Vaporizes the Rock\n";
cout << "You Lose, You get Nothing...Good Day Sir.." << endl;

}

else if (PlayerChoice == 1 && aI == 5)
{
cout << "The Computer Chose Spock\n";
cout << "You Chose Scissors\n";
cout << "Spock dismantles the Scissors\n";
cout << "You Lose, You get Nothing...Good Day Sir.." << endl;

}

else if (PlayerChoice == 3 && aI == 1)
{
cout << "The Computer Chose Scissors\n";
cout << "You Chose Paper\n";
cout << "Scissors cuts the Paper\n";
cout << "You Lose, You get Nothing...Good Day Sir.." << endl;
}


return 0;

}
}
Try a "do{}while()" loop..
It will always run the your code once.

example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

using namespace std;

int main() {

	char done; //user inpute ..one letter
	do //do{}while(); will run loop atleast once 
	{
		cout << "\nEnter 'y' to exit: ";
		cin >> done; 

	} while (done != 'y'); //will exit when the statment is true. 
}
tibrado wrote:
//will exit when the statment is true.

You mean false, don't you?
Yep.
That worked perfectly, thank you very much. I had tried a do while loop before. But i must of had something wrong because once it ran It would just loop thru all the outputs over and over and over...
Topic archived. No new replies allowed.