简体   繁体   English

在C函数中返回浮点值

[英]Returning a float value in a C function

First semester of CS. CS的第一学期。 When I change "%d" to "%f" the output is 10 times worse, not even showing the KPH row. 当我将“%d”更改为“%f”时,输出结果会恶化10倍,甚至没有显示KPH行。 Really not sure what I am doing wrong other than that. 真的不知道我在做什么错。 This is a screenie of what happens as it is now. 这是对现在情况的筛查。

Thanks for halpz I am n00b 感谢halpz我是n00b

#include<stdio.h>

float convertToMPH(float KPH);
float convertToKPH(float MPH);

int main(void){

    int i;

    puts("Kilometers per hour converted to miles per hour:");
    puts("Kph\tMph");


    for(i=185; i>=0; i-=5){
        printf("%d\t%d\n", i, convertToMPH(i));
    }
}

float convertToMPH(float KPH){
return (float) (KPH / 1.609344); 

}

http://i63.tinypic.com/24mhmk3.png

Change 更改

 printf("%d\t%d\n", i, convertToMPH(i));

to

 printf("%d\t%f\n", i, convertToMPH(i));

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

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