我写了一个程序并且结果有问题。当我输入一些数字时,例如43.01,条件运算符忽略该语句为真并给出错误输出(0美分),问题出在哪里?
int main()
{
double money_amount;
cout << "Enter money amount. For example: 3.59\n";
cin >> money_amount;
int dollar_amount = money_amount;
double cent_amount = money_amount - dollar_amount;
cout << cent_amount << "\n"; // to make sure that there is 0.01
dollar_amount == 1 ? cout << "You have 1 dollar\n" : cout << "You have " << dollar_amount << " dollars\n";
cent_amount == 0.01 ? cout << "You have 1 cent\n" : cout << "You have " << floor(cent_amount*100) << " cents\n"; // here is the problem
}