So basically I'm trying to create a simple buffer for input.
If the user inputs something other than the letter 'R' or 'S', then the do while loop will return the code back to where the user inputs the letter.
However, when I tried entering 'Z' for example, the loop repeats itself twice, asking for input on the second loop.
I don't understand why, please help me understand.
I tried... using a while loop? That doesn't work. I don't want to use goto.
<stdio.h>
<stdlib.h>
int main(void)
{
char r_or_s;
printf("Number Reverser/Shuffler v0.1\t");
printf("Written by REN\n");
printf("This program reverses and shuffles the order of numbers.\n\n");
do
{
printf("Would you like to reverse or shuffle numbers? (Press R/S):");
r_or_s = getchar();
printf("\n");
if (r_or_s == 'R')
{
reverseno();
}
else if (r_or_s == 'S')
{
shuffleno();
}
} while (r_or_s != 'R' || r_or_s != 'S');
return 0;
}
Expected output of
Would you like to reverse or shuffle numbers? (Press R/S):
after rejection of input, but the actual output is:
Would you like to reverse or shuffle numbers? (Press R/S): Would you like to reverse or shuffle numbers? (Press R/S):