Originally Posted by
Cess
ops... that was silly of me...that happen cuz I started over and it automatically had that part and I didn't double check it sorry..... I'm extremely new so ya sorry.
lets try this again..... why am I still getting errors...
Code:
#include <stdio.h>
#include <math.h>
int main()
{
{int number;
printf(" enter a positive number between 1 and 10:");
}
{if( (number < 1) || (number > 10) )
printf("The number is out of range. (1-10)\n");
}system("PAUSE");
return 0;
}
Because you are using the rules of scope incorrectly...
Code:
{int number; <--- you start a new scope here
printf(" enter a positive number between 1 and 10:");
} <-- you end it here, number is destroyed.
{if( (number < 1) || (number > 10) ) <--- you start another scope here but number is unknown
printf("The number is out of range. (1-10)\n");
} <--- you end the second scope here
Yes, that's right, those curly braces are active parts of the software, not merely window dressing.
try this...
Code:
#include <stdio.h>
#include <math.h>
int main()
{
int number;
printf(" enter a positive number between 1 and 10:");
scanf("%d",&number);
if( (number < 1) || (number > 10) )
printf("The number is out of range. (1-10)\n");
return 0;
}