Im coding a Rock Paper Scissors program and eveything works completely fine except for one thing. In the line of the else condition, the one that contains the while loop (choice != 1 || choice != 2 || choice != 3)
with the finishing break;
command, it only ever works when an inncorect input like 4 is entered once but not a second time.
When an incorrect input is entered the first time the program will ask for the input again but if you enter another inncorrect input it will just continously just keep printing the same printf line
printf("Please choose 1 for ROCK, 2 for PAPER or 3 for SCISSORS.\n");
and then proceed to just keep printing
Computer choice is ROCK. Please choose 1 for ROCK, 2 for PAPER or 3 for SCISSORS.
while (counter != 10) {
for (i=0;i<1;i++) {
/* Generate a random number and restrict it to the range 1 to 3 */
randNum = rand()%3+1;
/*printf("A random number between 1 and 3: %d\n", randNum);*/
}
printf("Please choose 1 for ROCK, 2 for PAPER or 3 for SCISSORS.\n");
scanf("%d", &choice);
/* User picks an option */
if ( choice == 1 ){
printf("User choice is ROCK.\n");
}
else if ( choice == 2 ){
printf("User choice is PAPER.\n");
}
else if ( choice == 3 ){
printf("User choice is SCISSORS.\n");
}
else {
while (choice != 1 || choice != 2 || choice != 3) {
printf("Please choose 1 for ROCK, 2 for PAPER or 3 for SCISSORS.\n");
scanf("%d", &choice);
break;
}
}
The output when I enter an incorrect input twice
Please choose 1 for ROCK, 2 for PAPER or 3 for SCISSORS.
4
Please choose 1 for ROCK, 2 for PAPER or 3 for SCISSORS.
4
Computer choice is ROCK.
Please choose 1 for ROCK, 2 for PAPER or 3 for SCISSORS.
I've already tried using a break command but even that doesnt fix the issue. What do I have to change in my program to fix this issue?