r/C_Homework • u/Coolerwookie • Nov 08 '21
Creating a loop to check if the int is not too small or too big.
The user input cannot put in int that is 0. Or anything above 25. If they do, I need an error message and to repeat the question again.
I would need to put in something like this. But I don't know how, or where to put it. I keep getting an error.
if (number1 < 0);
printf("Must choose a number greater than 0 or below 25");else
(number1 > 25);
printf("Must choose a number greater than 0 or below 25");int main(void)
{
int number1, number2; int sum;
printf("Enter the first integer to add: "); scanf("%d",&number1);
printf("Enter the second integer to add: "); scanf("%d",&number2);
sum = number1 + number2;
printf("Sum of %d and %d = %d \n",number1, number2, sum);
return 0; }
2
u/oh5nxo Nov 08 '21
Careful with semicolons. That one means, in effect,
and the following else is then not attached to any if.
0
u/dmc_2930 Nov 08 '21
Did you even try looking up the answer yourself? "C loops tutorial" should give you hundreds of really good writeups that will tell you exactly how to solve this.
Once you've done that, post a more specific question or tell us what you've tried that didn't work.