Write a program to score the paper - rock - scissor game. Each of two users types in 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.
Be sure to allow the users to use lowercase as well as uppercase letters. Your program should include a loop that lets the user play again until user says she or he is done.
1
Expert's answer
2012-09-14T10:47:21-0400
#include <conio.h> #include <iostream> using namespace std;
int main(){ & char z1,z2;
while (z1!='q' && z2!='q' ){
cout<<"User 1: "; & cin>>z1; & cout<<"User 2: "; & cin>>z2; & //p s r & if (z1=='p' || z1=='P' ){ & if (z2=='s' || z2=='S' ) cout<<"Defeated user 2\n"; else if (z2=='r' || z2=='R' ) cout<<"Defeated user 1\n"; else& if (z2=='P' || z2=='p' ) cout<<"nobody wins"; else & cout<<"Error\n"; & }
else& if& (z1=='r' || z1=='R'){ & if (z2=='s' || z2=='S' ) cout<<"Defeated user 1\n"; else& if (z2=='r' || z2=='R' ) cout<<"nobody wins\n"; else& if (z2=='P' || z2=='p' ) cout<<"Defeated user 1"; else & cout<<"Error\n"; } & else if& (z1=='s'& || z1=='S'){ & if (z2=='r' || z2=='R' ) cout<<"Defeated user 1\n"; & else if (z2=='P' || z2=='p' ) cout<<"nobody wins\n"; & else if (z2=='s' || z2=='S' ) cout<<"Defeated user 1"; else & cout<<"Error\n"; & } & else & cout<<"Error\n"; & cout<<"Enter 'q' to exit\n";
Comments
Leave a comment