hello, i am writing a code to simulate the game rock paper scissors, i have it working, but i have a small problem. the game asks for R P S or Q(quit), then it tells you the outcome of the game, then it prompts the used for another
R P S or Q. but instead of asking for it only once(for the second/third/fourth/etc prompt) , it prints the line twice. i was using fflush(stdin) but i don't want to use that. this is only a minor issue but i was wondering if someone could give me some suggestions to what i am doing wrong. thanks
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int random = rand() % 3;
int userWinCount = 0 ;
int computerWinCount = 0;
int tieCount = 0;
char choice;
printf("**Rock Paper Scissors Game**\n");
srand(time(NULL));
do
{
printf("\nPlease enter R, S, P or Q(Quit)\n");
scanf("%c" , &choice);
switch (random)
{
case 0:
switch (choice)
{
case 'R': case 'r':
printf("Same throw Rock. Game is tie\n");
tieCount++;
break;
case 'S': case 's':
printf("Rock breaks scissors! Computer wins\n!");
computerWinCount++;
break;
case 'P': case 'p':
printf("Paper covers rock! User wins\n!");
userWinCount++;
break;
}
break;
case 1:
switch ( choice )
{
case 'R': case 'r':
userWinCount++;
printf("Rock breaks scissors! User wins!\n");
break;
case 'S': case 's':
printf("Same throw Scissors. Game is tie\n");
tieCount++;
break;
case 'P': case 'p':
computerWinCount++;
printf("Scissors cut paper! Computer wins!\n");
break;
}
break;
case 2:
switch ( choice )
{
case 'R': case 'r':
printf("Paper covers rock! Computer wins!\n");
computerWinCount++;
break;
case 'S': case 's':
printf("Scissors cut paper! User wins!\n");
userWinCount++;
break;
case 'P': case 'p':
printf("Same throw Paper. Game is tie\n");
tieCount++;
break;
}
break;
}
}
while ( choice != 'Q' && choice != 'q' );
printf("Total User Wins = %d\n" , userWinCount);
printf("Total Computer Wins = %d\n" , computerWinCount );
printf("Total Tie Count = %d\n" , tieCount ) ;
system("pause");
return 0;
}