Вопрос

Why is that even if enter value 999999, it will always go to else statement? Can someone explain why and what is the correct way to do this?

#include <stdio.h>

int main(int argc, char **args)
{
    double dValue = 0;

    scanf("%d",&dValue);

    if(10000 < dValue){
            printf("More than");
    } else {
        printf("Less than");
    }

    return 0;
}
Это было полезно?

Решение

If you're intending to read in the value as an integer (using "%d"), then you should declare it to be an int. If you're intending to read in the value as a double, then you should instead use "%lf" as your scanf format specifier.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top