mardi 19 janvier 2021

C, add statement to check if input is an integer

This is currently what I have, I want to add a statement at the bottom the returns (printf("Error"); if the stuff entered isn't a number.

int main() {
    long long number;
    long long ret;
    
    printf("Enter a number between [0 - 4294967295]: ");
    scanf("%lld", &number);
    
    printf("Number is %lld\n", number);
    //if statements to see if number is above/below the range
    if (number < 0) {
        printf("Error: This number is below the range.");
        return -1;
    }
    if (number > 4294967295) {
        printf("Error: This number is above the range.");
        return -1;
    } 
    //this is where I would like to add the statement
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire