lundi 24 février 2020

Input characters not reading correctly

This should be a simple error. My code is basically reading a user input value and if the value is greater than 0 it will return the value. If not it will print an error and ask for the value again. The only problem is when a new value is input it uses the old false value without error.

int menuSize(int s) {
printf(" Please Enter size: ");
scanf("%i", &s);
if (s>0) {
}
else {
    printf(" Invalid Input\n");
    getchar();
    menuSize(s);
}
return s;
}

Aucun commentaire:

Enregistrer un commentaire