I actually have it working, but with using two if-statements. I was wondering if there was a better way to set the input limit, and why my one if-statement isn't working.
As I want to set a limit to a number inputted to 1 between 2000.
My working code with the two if-statements.
#include <stdio.h>
int main(){
int num;
printf("Please Enter a number between 1 and 2000\n");
scanf("%d", &num);
if(num > 2000 ){
printf("Your number isn't between 1 and 2000");
return 0;
}
if(num <= 0){
printf("Your number isn't between 1 and 2000");
return 0;
}
printf("%d", num);
return 0;
}
My single if-statement that isn't working
if(num > 2000 && num <= 0){
printf("Your number isn't between 1 and 2000");
return 0;
}
Aucun commentaire:
Enregistrer un commentaire