printf(\ n您输入的经过时间为%d小时和%d 分钟。\ nn,小时,分钟); getch(); // 2.30的输出总是2小时29分 返回0; } I have a problem with some simple math operations resulting in the wronginteger. Why am I getting the wrong integer back for 2.30? I should getback 2 hours and 30 minutes but instead I get 2 hours and 29 minutes. #include <stdio.h>int main(void){ double elapsed_time;int hours;int minutes; printf("Enter hours (hh.mm): ");scanf("%lf", &elapsed_time); //take the integer of 2.30 to get # of hours which is 2hours = elapsed_time; // Ex. (2.30 - 2) = 0.3 ===> (0.3 * 100) = 29 !?!?!?!?!?!?!?!?!?minutes = (elapsed_time - hours) * 100; printf("\nYou entered an elapsed time of %d hours and %dminutes.\n", hours, minutes);getch(); //Output for 2.30 is always 2 Hours and 29 minutes return 0;}推荐答案 在文章< 4bCJd.29090 In article <4bCJd.29090 IV5.21532@attbi_s54>, " Kelly Goode" <无**** @ none.com>写道: IV5.21532@attbi_s54>,"Kelly Goode" <no****@none.com> wrote: 我有一些简单的数学运算问题导致错误的整数。为什么我得到错误的整数回到2.30?我应该回来2小时30分钟,但我得到2小时29分钟。 I have a problem with some simple math operations resulting in the wrong integer. Why am I getting the wrong integer back for 2.30? I should get back 2 hours and 30 minutes but instead I get 2 hours and 29 minutes. 2.30不是2和30分;它是一个接近那个 的数字,因为C使用二进制浮点数而不是十进制浮动 点数。它可能略大或略小。检查你的计算是做什么的,如果它只是一点点不到两三十 百分之一。 2.30 is not two and thirty hundredths; it is a number close to thatbecause C uses binary floating point numbers and not decimal floatingpoint numbers. It may be slightly larger or slightly smaller. Check whatyour calculations do if it is just a tiny bit less than two and thirtyhundredths. Kelly Goode <无**** @ none.com>在留言中写道 news:4bCJd.29090 "Kelly Goode" <no****@none.com> wrote in messagenews:4bCJd.29090 这篇关于整数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 07:51