current position:Home>The green hand solves the floating point problem, the software is dev C++

The green hand solves the floating point problem, the software is dev C++

2022-08-06 04:33:37CSDN Q&A

Problem and background

According to the teaching of C language, the output should be a floating point number, that is, the input inch will affect the output result, but in fact, it does not affect
Add a problem, and suddenly found that it is no problem to run on vs.But not in dev.

#include
int main()
{
printf("Please enter height in feet and inches:");
double foot;
doubleinch;
scanf("%lf %lf", &foot, &inch);
printf("Height is %fm\n",( (foot + inch / 12.0) * 0.3048));
return 0;
}

Running result and error content

Please enter your height in feet and inches: 6 7
Height is 1.828800 meters


Process exited after 3.854 seconds with return value 0
Press any key to continue. . .

Please enter your height in feet and inches: 6 2
Height is 1.828800 meters


Process exited after 4.146 seconds with return value 0
Press any key to continue. . .

My solution ideas and tried methods

In the beginning, I just changed 12 to 12.0. It seems that this is ok, but it is useless, and then I changed the int to double

My desired outcome

Solve C

copyright notice
author[CSDN Q&A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/218/202207301315578675.html

Random recommended