ok, I tested the if statements that contain the string comparisons in order to determine whether the computer or player wins and it worked fine, yet when I put it in the program everything works up to that part, the player chooses a choice and then it shows the computer choice but it never prints the statement that says who won that round. I haven't gotten any error message..is there something wrong in my coding?
Code:
#include<iostream>
#include<math.h>
#include<string>
#include<stdlib.h>
#include<cstdlib>
#include<ctime>
int checkLoop;
char yesOrno[10]="";
using namespace std;
int main()
{
while(checkLoop == 0){
//intro screen
cout << " " << endl;
cout << " Rock Paper Scissors " << endl;
cout << " ____________________________________________________________________________" << endl;
cout << "| This is a game of rock, paper, scissors. You will the best of three rounds |" << endl;
cout << "| against the computer. To pick either rock, paper, or scissors simply | " << endl;
cout << "| type in your choice and hit enter. The computer will randomly pick its | " << endl;
cout << "| choice. At the end of the game type y to play again & n to end the game. | " << endl;
cout << "| Do you understand? please enter y or n | " << endl;
cout << "|____________________________________________________________________________| " << endl;
//user input
cin.getline(yesOrno, 10);
if((strcmp(yesOrno,"n")==0)||(strcmp(yesOrno,"y")==0)) //if the user input is a y or n go into this other loop
{
if(strcmp(yesOrno,"y")==0)
{
checkLoop=1;
system("CLS");
cout<< "Get ready to start the game"<<endl;
}
else //if the user input is no repeat the directions
{
system("CLS");
cout<< "Read the directions again";
checkLoop=0; //makes this loop repeat until y or n entered
}
}
else
{
cout<< " Enter a y or n "<<endl; //if the user enters something other than a y or n print this statement
cout<<endl;
cout<<endl;
}
}
string computerChoice;
char playerChoice[20]="";
cout << "Input player choice."<<endl;
cin.getline(playerChoice,10);
if((strcmp(playerChoice,"paper")==0)||(strcmp(playerChoice,"rock")==0)||(strcmp(playerChoice,"scissors")==0))
{
srand((unsigned)time(NULL));
int d=rand()%3;
if (d==0)
{
cout<<"Computer choice: Paper"<<endl;
computerChoice=="Paper";
}
if (d==1)
{
cout<<"Computer choice: Rock"<<endl;
computerChoice=="Rock";
}
if (d==2)
{
cout<<"Computer choice: Scissors"<<endl;
computerChoice=="Scissors";
}
cout<<d;
//this is the part that doesn't show up
if((strcmp(playerChoice,computerChoice.c_str()))==0)cout<<"Tie"<<endl;
if ((strcmp(playerChoice,computerChoice.c_str()))==2)cout<< " paper beats rock, computer wins this round"<<endl;
if((strcmp(playerChoice,computerChoice.c_str()))==3)cout<<"scissors over paper,player wins this round "<<endl;
if((strcmp(playerChoice,computerChoice.c_str()))==-2)cout<<"paper beats rock,player wins this round"<<endl;
if((strcmp(playerChoice,computerChoice.c_str()))==-3)cout<<"scissors beats paper, computer wins"<<endl;
if ((strcmp(playerChoice,computerChoice.c_str()))==1)cout<<"rock beats scissors, computer wins this round"<<endl;
if ((strcmp(playerChoice,computerChoice.c_str()))==-1)cout<<"rock beats scissors, player wins this round"<<endl;
}
else
{
cout<<"you made a mistake in typing"<<endl;
}
return 0;
}