-6

I'm having a problem with this C Programming activity. I'm new to C-Programming and would really like to ask you guys for your help. So please bear with me.

So here's the problem...

When I run the program as I enter my choice for Player Two the program automatically stops and closes. It wont even let me press "ENTER" before it closes. I tried everything else I can and looked for a solution online but to no avail. I am only allowed to use the conditional statement If-Else for this. I would really appreciate any suggestions. Thanks in advance.

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

void main(){
clrscr();
char one, two;

printf("\t\t\t      Rock-Paper-Scissors\n");
printf("Choose from the following:\n");
printf("r for Rock\np for Paper\ns for Scissors\n\n");
printf("Player One enter your choice: ");
scanf("%c",&one);
printf("Player Two enter your choice: ");
scanf("%c",&two);
printf("\n");


//rock over scissors
if (one == 'r' && two == 's'){
    printf("Rock Destroys Scissors\n");
    printf("Player One Wins!");
}
else if (two == 'r' && one == 's'){
    printf("Rock Destroys Scissors\n");
    printf("Player Two Wins!");
}
//paper over rock
else if (one == 'p' && two == 'r'){
    printf("Paper Covers Rock\n");
    printf("Player One Wins!");
}
else if (two == 'p' && one == 'r'){
    printf("Paper Covers Rock\n");
    printf("Player Two Wins!");
}
//scissors over paper
else if (one == 's' && two == 'p'){
    printf("Scissors Cut Paper\n");
    printf("Player One Wins!");
}
else if (two == 's' && one == 'p'){
    printf("Scissors Cut Paper\n");
    printf("Player Two Wins!");
}
else
    printf("It's a Tie!");
getch();
}

1 Answers1

1

Just change scanf("%c",&one); to scanf(" %c",&one); and scanf("%c",&two); to      scanf(" %c",&two);

scanf function seems to be skipped in c

suvojit_007
  • 1,690
  • 2
  • 17
  • 23
  • Thanks a lot @suvojit_007 . As I said I'm a newb in C and have no idea whatsoever what to do with it so thanks a lot for answering. – Ernest Mercado Oct 17 '18 at 14:42