-
double to float
I wrote a program converting fahrenheit to celsius but the requirement calls for using int for fahrenheit and float for celsius. Obviously thats leading to possible loss of data warnings. What can I do? And does anyone know why the "0" isn't showng in the celsius column? I think it was there but I changes something and now its gone? :confused:
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int fahrenheit;
float celsius;
int lower, upper, step;
printf( "Fahrenheit Celsius\n\n" );
lower = 0;
upper = 212;
step = 1;
fahrenheit = lower;
while (fahrenheit <= upper)
{
celsius = ( 5.0/9.0 ) * ( fahrenheit - 32.0 );
printf( "%10.0d %+10.3f\n", fahrenheit, celsius );
fahrenheit = fahrenheit + step;
}
return 0;
}
-
Do these changes
Code:
#include <stdlib.h>
int main()
{
int fahrenheit;
float celsius;
int lower, upper, step;
printf( "Fahrenheit Celsius\n\n" );
lower = 0;
upper = 212;
step = 1;
fahrenheit = lower;
while (fahrenheit <= upper)
{
celsius = ( 5.0f/9.0f ) * ( fahrenheit - 32.0f );
printf( "%10.0d %+10.3f\n", fahrenheit, celsius );
fahrenheit = fahrenheit + step;
}
return 0;
}
-
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
int fahrenheit;
float celsius;
int lower, upper, step;
printf( "Fahrenheit Celsius\n\n" );
lower = 0;
upper = 212;
step = 1;
fahrenheit = lower;
while (fahrenheit <= upper)
{
celsius = ( 5.0f/9.0f ) * ( fahrenheit - 32.0f );
printf( "%10.0d %+10.3f\n", fahrenheit, celsius );
fahrenheit = fahrenheit + step;
}
return 0;
}
ahihih