This is my first ever piece of code that ive developed independently and ive run into an issue. Ive Googled the issue and no prevail. I'm making a Rock Paper Scissors game and I have an input where you choose either Rock Paper or Scissors, after you choose, the program randomly outputs either Rock Paper or Scissors, now my issue is with the If statements after the random output, it only selects:
{
cout << ", you lose! Do you want to play again? (Yes / No)";
}
Whereas this is my code here:
#include <iostream>
#include <string>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{
// yn = yes / no
string yn;
cout << "Do you want to play Rock, Paper, Scissors? (Yes / No) ";
cin >> yn;
if (yn == "Yes")
{
// rps = rock paper scissors
string rps;
cout << "Choose, Rock, Paper, or Scissors\n";
cin >> rps;
if (rps == "Rock")
{
// Randomizer
srand(time(0));
string rpslist[3] = { "Rock", "Paper", "Scissors " };
int rpsnumber = rand() % 3;
cout << "I choose: " << rpslist[rpsnumber];
if (rpslist[1] == "Rock")
{
cout << ", we draw! Do you want to play again? (Yes / No)";
}
if (rpslist[2] == "Paper");
{
cout << ", you lose! Do you want to play again? (Yes / No)";
}
if (rpslist[3] == "Scissors")
{
cout << ", you win! Do you want to play again? (Yes / No)";
}
}
Aucun commentaire:
Enregistrer un commentaire