[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
help with (error ISO c++ forbids comparison between pointers and integer
From: |
Josh Henry |
Subject: |
help with (error ISO c++ forbids comparison between pointers and integers |
Date: |
Sat, 9 Apr 2011 16:40:40 -0700 (PDT) |
User-agent: |
G2/1.0 |
heres the code writing it for a rock papers scissors game cannot
figure out whats wrong its suppose to be a user vs computer program
that uses a random number generator to make the comp selection and
then output the winner and each of the user and comp choice in char
not (0,1,2)???
#include <iostream>
using namespace std;
#include <ctime>
#include <cstdlib>
char usersMove()
{
char user = 'Q';
do
{
cout << "Welcome to the game of Rock, Paper, Scissors." << endl;
cout << "Please chose your weapon: [R for rock, P for paper, S for
scissors, and Q to quit]: " << endl;
cin >> user;
cin.ignore(1000, 10);
if (user == 'R' || user == 'r' || user == 'P' || user == 'p' ||
user == 'S' || user == 's');
if (user == 'Q' || user == 'q') break;
{
return tolower(user);
}
}
while (true);
}
char comp()
{
int compChoice = rand() % 3;
if (compChoice == 0) return 'r';
else if (compChoice == 1) return 'p';
return 's';
}
int whoWins(char userPick,char compPick)
{
if (userPick == 'R' || userPick == 'r')
{
if (compPick == 'R' || compPick == 'r')
return 2;
else if (compPick == 'P' || compPick == 'p')
return 1;
else
return 0;
}
else if (userPick == 'P' || userPick == 'p')
{
if (compPick == 'P' || compPick == 'p')
return 2;
else if (compPick == 'S' || compPick == 's')
return 1;
else
return 0;
}
else if (userPick == 'S' || userPick =='s')
{
if (compPick == 'S' || compPick == 's')
return 2;
else if (compPick == 'R' || compPick == 'r')
return 1;
else
return 0;
}
return 0;
}
int main()
{
srand(time(0));
char user, ai;
int winner;
user = usersMove();
ai = comp();
cout << "The computer chose " << ai;
winner = whoWins(user, ai);
if (whoWins == 0)
cout << "You win!";
else if (whoWins == 1)
cout << "You lost.. ";
else
cout << "You tied";
return 0;
}
- help with (error ISO c++ forbids comparison between pointers and integers,
Josh Henry <=