(int) withdrawAmount %= 50;
应替换为
withdrawAmount = std::fmod(withdrawAmount, 50);
其他值也一样(别忘了
#include <cmath>
).
作为替代方案:
double input; //declare variable to store use input for desired withdraw amount
do { //Ask for valid user input
cout << "Please enter an amount to withdraw from yor account" << endl;
cin >> input; //save user input into withdrawAmount variable
} while (input < 1);
int withdrawAmount = input; // rounded toward 0.
std::cout << "$50 bills :"<< withdrawAmount / 50 << std::endl;
withdrawAmount %= 50;
// And so on...
// Final remaining
std::cout << "Remaining: " << input - int(input) << std::endl;