Hi,
I just started with C like 1 week ago and Ive never coded in my life so bear with me as I always try to code stuff from the top of my head that Ive already learned so its really just a very simple code ...
Code:
#include<stdio.h>
int main(void)
{
char c;
//ask user
while (!(c == 'y' || c == 'Y' || c == 'n' || c == 'N')) {
printf("Do you agree?: ");
scanf("%c", &c);
if (c == 'y' || c == 'Y')
printf("I agree\n");
else if(c == 'n' || c == 'N')
printf("I disagree\n");
}
}
The purpose of this code is to ask the user if he "Agrees" and if he types in anything else than "Y/y or N/n" it asks the user again in a loop.
Now the problem is that if you enter any other charakter than "Y/y /N/n" it always prints "Do you agree?: " twice in a row and I cant figure out why.
Thanks in advance.