- Code: Select all
#include <stdio.h>
int main()
{
int num;
printf("Please enter a number: ");
scanf("%d", &num); /*You pressed enter here . . .*/
if(0<num, num<5){/* || means or, 0<num<5 is the same as 0<num || num<5 ?*/
printf("You entered %d, this number is between 0 and 5.", num);
}
else if(num>5, num<100){
printf("You entered %d, this number is larger than 5 but smaller than 100", num);
}
else {
printf("The number is larger than 100.");
}
getchar(); /*So you must place a getchar(); here to cancel it out?*/
getchar();
}
Then I tried to change the layout a bit so that it looked like this
- Code: Select all
#include <stdio.h>
int main()
{
int num;
printf("Please enter a number: ");
scanf("%d", &num); /*You pressed enter here . . .*/
if(0<num, num<5){/* || means or, 0<num<5 is the same as 0<num || num<5 ?*/
printf("You entered %d, this number is between 0 and 5.", num);
}
else if(num>5, num<100){
printf("You entered %d, this number is larger than 5 but smaller than 100", num);
}
else {
printf("The number is larger than 100.");
}
getchar(); /*So you must place a getchar(); here to cancel it out?*/
getchar();
}
and then I tried (by coincidence) to only pull the last most curly bracket up one line, and it worked!?
- Code: Select all
#include <stdio.h>
int main()
{
int num;
printf("Please enter a number: ");
scanf("%d", &num); /*You pressed enter here . . .*/
if(0<num, num<5){/* || means or, 0<num<5 is the same as 0<num || num<5 ?*/
printf("You entered %d, this number is between 0 and 5.", num);
}
else if(num>5, num<100){
printf("You entered %d, this number is larger than 5 but smaller than 100", num);
}
else {
printf("The number is larger than 100.");
}
getchar(); /*So you must place a getchar(); here to cancel it out?*/
getchar();
}
I tend to get this msg a lot when I got my codes correct sometimes, what is causing this? Or is the problem really lie in the code I use? Thanks in advance for any help, have a nice day.



