#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main(void)
{
int loonies, quarters ;
double amountdue, balanceowing, owing;
printf("Please enter the amount to be paid: $");
scanf("%lf", &amountdue);
loonies = amountdue / 1;
balanceowing = (amountdue - (int)amountdue);
quarters = (balanceowing / 0.25);
owing = ((int)(balanceowing*100) % 25);
printf("Loonies required: %d, balance owing $%.2lf\n", loonies, balanceowing);
printf("Quarters required: %d, balance owing $%.2lf", quarters , owing/100);
return 0;
}
我要输入值8.68并获取输出
Please enter the amount to be paid: $8.68
Loonies required: 8, balance owing $0.68
Quarters required: 2, balance owing $0.18
这是我通过解决方案得到的输出
Please enter the amount to be paid: $8.68
Loonies required: 8, balance owing $0.68
Quarters required: 2, balance owing $0.17
为什么欠值返回的值= 0.17? 68 mod 25 = 18
这是四舍五入吗?