What am i doing wrong with my code?
#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;
ok now I have fixed everything except now I am getting a ISO C++ forbids comparison between pointers and integers heres the new code
#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;
ok yeah no. your code is really messed up from what i see. Clean it up and post in using the [code] tags, but from my glance your parenthesis are all over the place.
char rockPaperScissors()
while (true) {
char user = 'Q';
cout << "This is the game rock, paper, scissors." << endl;
again:
cout << "Choose: (0 for rock, 1 for paper, 2 for scissors or Q to quit):" << endl;
cin >> user;
cin.ignore(1000, 10);
if (user == '0' || user == '1' || user == '2') return user; //NOT BREAK AS IT WILL RETURN Q (QUIT)
if (user == 'Q' || user == 'q') break; //HERE BREAK IS OK
cout << user << " This was not a valid choice, please select again. " << endl;
goto again; //NOT BREAK AS IT WILL RETURN ANYTHING
}
fixed that but still getting multiple results in who wins or ties.... get the correct answer followed by a random such as..
Choose: (0 for rock, 1 for paper, 2 for scissors or Q to quit):
0
You lose, paper beats rock.
break things up into functions it will help ALOT. oh and for future reference only put the parts of the code that are getting errors so that other people do not have to wade through your code.
phew.. this took a while to get your code to work.. alot of editing =P be more observant about your brackets, and remember that you made the user a charactor variable, not an int
and characters are put between single quotes, like this 'a'
I coded my own rock paper scissors game after reading this just for fun and practice. Let me know what you think and if you think I could have done anything better. I could have broken this down into functions, but I don't see the point with how simple and short this code is.