Click here to Skip to main content
15,122,845 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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

What I have tried:

#include <stdio.h>
#include <conio.h>

main(){
char p1, p2;
clrscr();

gotoxy(26,4);cprintf("R=ROCK S=SCISSORS P=PAPER");
gotoxy(26,5);cprintf("PAPER ROCK SCISSORS GAME");

gotoxy(26,6);cprintf("Player 1: ");
scanf("%c", &p1);

gotoxy(26,);cprintf("Player 2: ");
scanf("%c", &p2);


switch(p1)
{

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;

}

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");
}

getch();

}
Posted
Updated 30-Sep-21 6:22am
Comments
Member 15329613 30-Sep-21 10:26am
   
What is your question?
xtianrtiaga 30-Sep-21 10:30am
   
How to create program in turbo c++ using <stdio.h> <conio.h> ,switch/case

for the problem:

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
xtianrtiaga 30-Sep-21 10:30am
   
please help me. thank you

See PLEASE HELP in TURBO C++[^]. The two of you should share ideas.
   
Comments
OriginalGriff 30-Sep-21 12:11pm
   
I thought the homework question looked familiar! :laugh:
xtianrtiaga 1-Oct-21 6:44am
   
oh,I see
The way I'd do it is with a simple function: pass it the two guesses and it returns a string.

Inside the function, I'd use a 2D array of char pointers, and use the inputs as the two indexes. the string is the result. Convert 'S', 'R', and 'P' to 0, 1, and 2 then just use those to index the array.
No if is needed!

In fact, I'd expand it slightly to have four index values: Stone, Rock, Paper and "other" with "other" returning a "unknown input" message. Again, an array would be a simple way to check and convert the inputs:
C
int InputToIndex(char c)
    {
    static const char inputs[3] = "SRP";
    int i;
    for (i = 0; i < sizeof(inputs); i++)
       {
       if (inputs[i] == c) break;
       }
    return i;
    }
   
v2
Comments
xtianrtiaga 30-Sep-21 11:26am
   
yes, but that program want me use the printf and scanf :(
OriginalGriff 30-Sep-21 12:10pm
   
So do.
None of what I said affects any input or output ...
xtianrtiaga 30-Sep-21 12:20pm
   
#include <stdio.h>
#include <conio.h>

main(){

this is what I've tried
char p1, p2;
clrscr();

gotoxy(26,4);cprintf("R=ROCK S=SCISSORS P=PAPER");
gotoxy(26,5);cprintf("PAPER ROCK SCISSORS GAME");

gotoxy(26,6);cprintf("Player 1: ");
scanf("%c", &p1);

gotoxy(26,);cprintf("Player 2: ");
scanf("%c", &p2);


switch(p1)
{

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;

}

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");
}

getch();

}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900