I'm doing a Rock Paper Scissors game for my next plate, I think there's something missing I just can't figure out what. Here's what I've done so far, all I need is to get the result on who wins to show up like "PLayer 1 Wins" or "It's a tie". Could it be the looping? The char initialization also seems wrong. Please enlighten me, I'm grateful for any answers! This is what the output shows.
Edited:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <stdlib.h>
#include <Windows.h>
using namespace std;
class Game
{
private: int rndNum, result;
char P1, P2, repeat;
const char R = 'R', S = 'S', P = 'P';
public: void RSPLogic();
};
void Game::RSPLogic()
{
do {
cout << "Input choice of player 1 : ";
cin >> P1;
cout << "Input choice of player 2 : ";
srand(time(0));
rndNum = rand() % 3;
if (rndNum == 0) //Computer rock
{
P2 = 0;
cout << "R\n";
}
else if (rndNum == 1) //Computer scissors
{
P2 = 1;
cout << "P\n";
}
else if (rndNum == 2) // Computer paper
{
P2 = 2;
cout << "S\n";
}
//Player 1 Win
if ((P1 == 'R' && P2 == 1) || (P1 == 'S' && P2 == 2) || (P1 = 'P' && P2 == 0))
cout << endl << "Player 1 Wins!" << endl << endl;
//Player 2 Win
else if ((P1 == 'R' && P2 == 2) || (P1 == 'S' && P2 == 0) || (P1 == 'P' && P2 == 1))
cout << endl << "Player 2 Wins!" << endl << endl;
//Tie
else if ((P1 == 'R' && P2 == 0) || (P1 == 'S' && P2 == 1) || (P1 == 'P' && P2 == 2))
cout << endl << " It's a Tie!" << endl << endl;
cout << endl << "Press [Y/y] to continue." << endl;
cin >> repeat;
repeat = toupper(repeat);
}
while (repeat == 'Y');
}
int main()
{
Game obj;
obj.RSPLogic();
system("pause");
return 0;
}