问题:你有1.45美元我们怎样才能输出这个是多少分之三和一角钱
产量应为5季度2角钱1镍。
double amount = 1.45
double quarter = .25
double dime = .10
double nickel = .05
if(fmod (amount,quarter) == 0)
cout << "your change is"<< amount/quarter << " quarters" ;
答案 0 :(得分:1)
转换为美分(使用int算术得分,因为它是离散值)为1.45 * 100然后
int quarters = 145 / 25;
int dimes = ( 145 - quarters * 25 ) / 10;
int nickels = ( 145 - quarters * 25 - dimes * 10 ) / 5;