简体   繁体   English

浮动不起作用,否则else语句(c)

[英]float not working in if else statement (c)

Whenever I try to use a float value in this IF ELSE statement it gives me 0 or an incorrect answer. 每当我尝试在此IF ELSE statement使用浮点值时,都会给我0或错误的答案。 I have used INT for the rest of the code and the rest works fine. 我将INT用于其余的代码,其余的工作正常。 This is the first time I have used float in the code and now it's not giving me the answer I want. 这是我第一次在代码中使用float,但是现在并没有给我想要的答案。

Can you please tell me what am I doing wrong? 你能告诉我我在做什么错吗?

float interestrate;

    if (month < 49)
    {
        interestrate = (0.063);
    }
    else if (salary <= 25000)
    {
        interestrate = (0.033);
    }
    else if (salary > 45000)
    {
        interestrate = (0.063);
    }
    else
    {
        interestrate = (0.033+(salaryabovethreshold*0.0000015));
    }

    printf("Interest Rate: %d \n", interestrate);

The %d format specifier is for int s, not float s. %d格式说明符用于int ,而不是float Try %f , %e or %g or %a for floating-point types. 对于浮点类型,请尝试%f%e%g%a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM