Answer to Question #243723 in C++ for xtian

Question #243723
Write a program that will simulate the Paper, Rock, Scissors game. Two players should be able to either P, R or S then the program shall determine who the winner is and state why he wins based on the following criteria

Paper covers Rock
Scissor cut paper
Rock breaks scissors


Sample Output
PAPER ROCK SCISSORS GAME
Player 1: P Player 2: S

Player 2 wins. Scissors cut Paper


please use ,
#include<stdio.h>
#include<conio.h>

scanf:
printf
1
Expert's answer
2021-09-29T01:17:25-0400
#include <stdio.h>
#include <conio.h>
using namespace std;
int main(){
    char p1, p2;
    
    printf("PAPER ROCK SCISSORS GAME\n");
    
    printf("Player 1: ");
    scanf("%c", &p1); 
    fseek(stdin, 0, SEEK_END);
    printf("Player 2: ");
    scanf("%c", &p2);


    switch(p1){
        case 'P': switch(p2){
            case 'P': printf("draw"); break;
            case 'R': printf("Player 1 wins. Paper covers Rock\n"); break;
            case 'S': printf("Player 2 wins. Scissors cut Paper\n"); break;
            default: break;
        } break;
        case 'R': switch(p2){
            case 'R': printf("draw"); break;
            case 'S': printf("Player 1 wins. Rock breaks Scissors\n"); break;
            case 'P': printf("Player 2 wins. Paper covers Rock\n"); break;
            default: break;
        } break;
        case 'S': switch(p2){
            case 'S': printf("draw"); break;
            case 'P': printf("Player 1 wins. Scissors cut Paper\n"); break;
            case 'R': printf("Player 2 wins. Rock breaks Scissors\n"); break;
            default: break;
        } break;
        default: break;
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS