- Jun 10, 2008
- 136
- 0
- 0
Hi,
I have to create a rock-paper-scissor game. Each of two users types in either P, R, or S. The program then announces the winner as well as the basis for determining the winner: Paper covers rock, Rock breaks scissors, Scissors cut paper, or Nobody wins. I have to allow the users to use lowercase as well as uppercase letters. The program should include a loop that lets the user play again until the user says she or he is done.
Here is my code:
#include <iostream>
using namespace std;
// Filename: Programming Project 1 Chapter 3.cpp
// Author: Anish
// Description: A program to play rock-paper-scissors.
// Date: Saturday, July 20, 2008
// Compiler: Visual C++ 2008 Express Edition
int main ( )
{
char play, one, two, y, Y, p, P, r, R, s, S;
cout << "This is a program that allows you to play rock-paper-scissors.\n"
<< "Would you like to play a game?\n"
<< "Press y for yes or n for no and press enter.\n\n";
cin >> play;
while (play == 'y' || play == 'Y')
{
cout << "Welcome to rock-paper-scissors.\n\n"
<< "Player one: Please choose rock, paper, or scissors.\n"
<< "For paper press p and then enter.\n"
<< "For rock press r and then enter.\n"
<< "For scissors press p and then enter.\n";
cin >> one;
cout << "Player one chose: " << one << ".\n"
<< "Player two: Please choose rock, paper, or scissors.\n"
<< "For paper press p and then enter.\n"
<< "For rock press r and then enter.\n"
<< "For scissors press p and then enter.\n";
cin >> two;
cout << "Player two chose: " << two << ".\n\n";
{
if (one == 'p' || one == 'P'; two == 'p' || two == 'P')
cout << "Nobody wins because you both chose paper.\n";
else if (one == 'p' || one == 'P'; two == 'r' || two == 'R')
cout << "Player one wins because paper covers rock.\n";
else if (one == 'p' || one == 'P'; two == 's' || two == 'S')
cout << "Player two wins because scissors cut paper.\n";
else if (one == 'r' || one == 'R'; two == 'p' || two == 'P')
cout << "Player two wins because paper covers rock.\n";
else if (one == 'r' || one == 'R'; two == 'r' || two == 'R')
cout << "Nobody wins because you both choose rock.\n";
else if (one == 'r' || one == 'R'; two == 's' || two == 'S')
cout << "Player one wins because rock breaks scissors.\n";
else if (one == 's' || one == 'S'; two == 'p' || two == 'P')
cout << "Player one wins because scissors cut paper.\n";
else if (one == 's' || one == 'S'; two == 'r' || two == 'R')
cout << "Player two wins because rock breaks scissors.\n";
else if (one == 's' || one == 'S'; two == 's' || two == 'S')
cout << "Nobody wins because you both choose scissors.\n";
else if (!(one == 'p' || one == 'P' || one == 'r' || one == 'R' || one == 's' || one 'S'))
cout << "Player one: " << player_ one << " is not a valid selection.\n"
<< "Please play again and choose a valid selection.\n";
else if (!(two == 'p' || two == 'P' || two == 'r' || two == 'R' || two == 's' || two 'S'))
cout << "Player two: " << two << " is not a valid selection.\n"
<< "Please play again and choose a valid selection.\n";
}
}
char c;
cout << "\n"
<< "Press a key and hit enter to exit.\n";
cin >> c;
return 0;
}
Thanks for the help. My compiler says I have 41 errors.
I have to create a rock-paper-scissor game. Each of two users types in either P, R, or S. The program then announces the winner as well as the basis for determining the winner: Paper covers rock, Rock breaks scissors, Scissors cut paper, or Nobody wins. I have to allow the users to use lowercase as well as uppercase letters. The program should include a loop that lets the user play again until the user says she or he is done.
Here is my code:
#include <iostream>
using namespace std;
// Filename: Programming Project 1 Chapter 3.cpp
// Author: Anish
// Description: A program to play rock-paper-scissors.
// Date: Saturday, July 20, 2008
// Compiler: Visual C++ 2008 Express Edition
int main ( )
{
char play, one, two, y, Y, p, P, r, R, s, S;
cout << "This is a program that allows you to play rock-paper-scissors.\n"
<< "Would you like to play a game?\n"
<< "Press y for yes or n for no and press enter.\n\n";
cin >> play;
while (play == 'y' || play == 'Y')
{
cout << "Welcome to rock-paper-scissors.\n\n"
<< "Player one: Please choose rock, paper, or scissors.\n"
<< "For paper press p and then enter.\n"
<< "For rock press r and then enter.\n"
<< "For scissors press p and then enter.\n";
cin >> one;
cout << "Player one chose: " << one << ".\n"
<< "Player two: Please choose rock, paper, or scissors.\n"
<< "For paper press p and then enter.\n"
<< "For rock press r and then enter.\n"
<< "For scissors press p and then enter.\n";
cin >> two;
cout << "Player two chose: " << two << ".\n\n";
{
if (one == 'p' || one == 'P'; two == 'p' || two == 'P')
cout << "Nobody wins because you both chose paper.\n";
else if (one == 'p' || one == 'P'; two == 'r' || two == 'R')
cout << "Player one wins because paper covers rock.\n";
else if (one == 'p' || one == 'P'; two == 's' || two == 'S')
cout << "Player two wins because scissors cut paper.\n";
else if (one == 'r' || one == 'R'; two == 'p' || two == 'P')
cout << "Player two wins because paper covers rock.\n";
else if (one == 'r' || one == 'R'; two == 'r' || two == 'R')
cout << "Nobody wins because you both choose rock.\n";
else if (one == 'r' || one == 'R'; two == 's' || two == 'S')
cout << "Player one wins because rock breaks scissors.\n";
else if (one == 's' || one == 'S'; two == 'p' || two == 'P')
cout << "Player one wins because scissors cut paper.\n";
else if (one == 's' || one == 'S'; two == 'r' || two == 'R')
cout << "Player two wins because rock breaks scissors.\n";
else if (one == 's' || one == 'S'; two == 's' || two == 'S')
cout << "Nobody wins because you both choose scissors.\n";
else if (!(one == 'p' || one == 'P' || one == 'r' || one == 'R' || one == 's' || one 'S'))
cout << "Player one: " << player_ one << " is not a valid selection.\n"
<< "Please play again and choose a valid selection.\n";
else if (!(two == 'p' || two == 'P' || two == 'r' || two == 'R' || two == 's' || two 'S'))
cout << "Player two: " << two << " is not a valid selection.\n"
<< "Please play again and choose a valid selection.\n";
}
}
char c;
cout << "\n"
<< "Press a key and hit enter to exit.\n";
cin >> c;
return 0;
}
Thanks for the help. My compiler says I have 41 errors.