Problem:
Hello good people,
I just completed the basic C++ programming course by taking help from a YouTube channel. It was a 15-days long course. After completing the course they give an exercise/assignment. They asked me to write a program of Rock-Paper-Scissors game of two players. So, I gave it a try and write some codes to make a game like that. Find my sample code snippet below and dig into it, please
#include <iostream>
#include <cstdlib>
#include <stdio.h>
using namespace std;
int main()
{
string fp;
string sp;
string r;
string p;
string s;
cout << "Rock, Paper, Scissors Game\n";
cout << "\nPlayer One, please enter your move: ('p' for Paper, 'r' for Rock, 's' for Scissor)";
cin >> fp;
cout << "\nPlayer Two, please enter your move: ('p' for Paper, 'r' for Rock, 's' for Scissor)";
cin >> sp;
if (fp == sp)
{
cout <<"\nThere is a tie"<<endl;
}
if ( fp == r && sp == p)
{
cout << "\nPaper wraps rock, Player 1 win";
}
else if (fp == r && sp == s)
{
cout << "\nRock smashes scissors, player 1 win";
}
if (fp == p && sp == r)
{
cout <<"\nPaper wraps rock, player 1 win";
}
else if ( fp == p && sp == s)
{
cout <<"\nScissors cut paper, player 2 win";
}
if ( fp == r && sp == p)
{
cout << "\nPaper wraps rock, Player 1 win";
}
else if (fp == r && sp == s)
{
cout << "\nRock smashes scissors, player 1 win";
}
if (fp == p && sp == r)
{
cout <<"\nPaper wraps rock, player 1 win";
}
else if ( fp == p && sp == s)
{
cout <<"\nScissors cut paper, player 2 win";
}
if ( sp == s && fp == r)
{
cout <<"\nScissors cut paper, player 1 win";
}
else if (sp == s && fp == p)
{
cout <<"\nRock smashes scissors, player 2 win ";
}
return 0;
}
The above program is not printing any results. I tried so hard but still couldn’t figure the problem in my codes. Could anybody please save me this time?
Thanks for your kind help.