1991dan
October 5th, 2009, 11:58 PM
I have the following block of code...
int counter2 = 0;
while(counter2 < 1) {
printf("What time of the day were you travelling at? Was it at the peak
scanf("%d", &timeofday);
if(timeofday == 1 || timeofday ==2) {
counter2 = counter2 + 1;
}
else
printf("ERROR; incorrect input.");
}
I wanted to keep prompting the user for this question until the integer "1" is entered. I don't think the IF statement is ever true regardless if I were to enter a 1, or not. Simply because I am comparing the input from the user with an integer, which i believe is the problem. But.. how would i be able to fix this?
int counter2 = 0;
while(counter2 < 1) {
printf("What time of the day were you travelling at? Was it at the peak
scanf("%d", &timeofday);
if(timeofday == 1 || timeofday ==2) {
counter2 = counter2 + 1;
}
else
printf("ERROR; incorrect input.");
}
I wanted to keep prompting the user for this question until the integer "1" is entered. I don't think the IF statement is ever true regardless if I were to enter a 1, or not. Simply because I am comparing the input from the user with an integer, which i believe is the problem. But.. how would i be able to fix this?