(Financial application: monetary units) Rewrite Listing, ComputeChange.cpp, to fix the possible loss of accuracy when converting a float value to an int value. Enter the input as an integer whose last two digits represent the cents. For example, the input 1156 represents 11 dollars and 56 cents.
Listing ComputeChange.cpp
1 #include2 using namespace std;34 int main()5 {6 // Receive the amount7 cout << "Enter an amount in double, for example 11.56: ";8 double amount;9 cin >> amount;1011 int remainingAmount = static_cast (amount * 100);12 13 // Find the number of one dollarsdollars 14 int numberOfOneDollars = remainingAmount / 100; 15 remainingAmount = remainingAmount % 100;1617 // Find the number of quarters in the remaining amountquarters 18 int numberOfQuarters = remainingAmount / 25; 19 remainingAmount = remainingAmount % 25;2021 // Find the number of dimes in the remaining amountdimes 22 int numberOfDimes = remainingAmount / 10; 23 remainingAmount = remainingAmount % 10;2425 // Find the number of nickels in the remaining amountnickels 26 int numberOfNickels = remainingAmount / 5; 27 remainingAmount = remainingAmount % 5;2829 // Find the number of pennies in the remaining amountpennies 30 int numberOfPennies = remainingAmount; 3132 // Display resultsoutput 33 cout << "Your amount " << amount << " consists of " << end⌉ <<34 " " << numberOfOneDollars << " dollars " << end⌉ <<35 " " << numberOfQuarters << " quarters " << end⌉ <<36 " " << numberOfDimes << " dimes " << end⌉ <<37 " " << numberOfNickels << " nickels " << end⌉ <<38 " " << numberOfPennies << " pennies " << end⌉;3940 return 0 ;41 }
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.