currently working on assignment , bit stuck. convert temperature celsius fahrenheit. final answer should output floating point number if answer decimal, or integer if it's whole number. have set give me floating point number, when enter number, '98.6', i'll 37.00000 rather 37. been @ few hours trying combat on own i've run out of ideas. assistance!
int main(void) { float ftemp; float ctemp; printf ("enter temperature in fahrenheit: "); scanf ("%f", &ftemp); ctemp = (100.0 / 180.0) * (ftemp - 32); printf ("in celsius, temperature %f!\n", ctemp); return 0; }
there isn't way have described. sounds want better string formatting. try using %g
instead of %f
in printf
(per this post).
e.g.
printf ("in celsius, temperature %g!\n", ctemp);
now, if hell bent on getting use integer, closest can come with:
int main(void) { float ftemp; float ctemp; int ctempi; printf ("enter temperature in fahrenheit: "); scanf ("%f", &ftemp); ctemp = (100.0 / 180.0) * (ftemp - 32); ctempi = (int)ctemp; if(ctemp == ctempi) { printf("in celsius, temperature %d\n", ctempi); } else { printf ("in celsius, temperature %f!\n", ctemp); } return 0;
}
Comments
Post a Comment