QuestionQuestion

A player cashes a Money Order with you.
Convert their money into the MINIMUM NUMBER of coins, so it's not too heavy.

Write a console application to convert the player's money order into the minimum number of US Coins.

Prompt the user for a sum of money
"Enter total cash: "
Input the user's response in the form DDDD.CC
Calculates the sum in US Coins: 25 cents, 10 cents, 5 cents, and 1 cent.
(Use the minimum number of coins and don't make any rounding errors.)
Output the totals:

Enter total cash: 12.34
Total: quarters:49
dimes:0
nickles:1
pennies:4

Consider the % operator: 0 == 8 % 2   and   2 == 17 % 5
% is the "modulus" operator, the remainder after dividing one number
by another.

Be sure to check your work with pencil and paper or a calculator.

Remember:

Take the total amount into a double, multiply the double by 100 to change the amount to total pennies. Store that in an int, and use ints from there on.

This, obviously, is a problem in division and subtraction.

If I have $ 365.29, the number of Quarters in that sum is equal to 365.25 divided by 0.25, right?

365.25 * 100 = 36529 store that in total

quarters are 36529 / 25
quarters are 1461
subtract 1451 * 25 from total
total is now 254
dimes are 254 / 10
dimes are 25
subtract 25 * 10 from total
total is now 4
nickels are total / 5
nickels are 0
(you can subtract 0 from total if you're OCD)
(total is still 4)
pennies are what is left in total
(pennies are 4)

Now I've accounted for all the money using the biggest coins first, so 1451 Quarters, 25 Dimes, 0 Nickels and 4 Pennies is the right answer.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

int main(int argc, char** argv) {
    double notes;   
    cout<<"Enter total cash: ";
    cin>>notes;
    notes *= 100;
    int coins = (int) notes;
    int left = coins % 25;...
$10.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats