I am using this on Windows and I can't get it to run properly, although it compiles without any problem. The idea of the program is simple: it first is supposed to ask player 1 to enter paper, rock or scissors, and then after they input their answer, it will ask player 2 the same thing and is supposed to tell you who wins, but the program keeps closing after player 2 enters their choice! Any suggestions or advice?
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string rock;
string paper;
string scissors; // declare rock, paper, and scissors
string player1;
string player2; // declare value of player 2
cout<<"Player One, enter paper, rock, or scissors: "; // output to player one to enter
// declare value of player 1
cin>>player1; //input from player 1
cout<<endl;
cout<<"Player Two, enter paper, rock or scissors: "; // output to player two to enter
cin>>player2; // input from player 2
cout<<endl;
if (player1==rock && player2==rock)
{
cout<<"It's a tie!";
}
else if (player1==rock && player2==paper)
{
cout<<"Player Two wins!";
}
else if (player1==rock && player2==scissors)
{
cout<<"Player One wins!";
}
else if (player1==paper && player2==paper)
{
cout<<"It's a tie!";
}
else if (player1==paper && player2==rock)
{
cout<<"Player One wins!";
}
else if (player1==paper && player2==scissors)
{
cout<<"Player Two wins!";
}
else if (player1==scissors && player2==scissors)
{
cout<<"It's a tie!";
}
else if (player1==scissors && player2==rock)
{
cout<<"Player Two wins!";
}
else if (player1==scissors && player2==paper)
{
cout<<"Player One wins!";
}
else
{
cout<<"Please try again..."<<endl;
}
system("pause");
return 0;
}