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