Search code examples
creturn

Returning a float value in a C function


First semester of CS. When I change "%d" to "%f" the output is 10 times worse, not even showing the KPH row. 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

#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


Solution

  • Change

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

    to

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