Question

Write a program that tells what coins to give out for as change from 1 cent...

Write a program that tells what coins to give out for as change from 1 cent to 99 cents. Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies) only. Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program.


Solution Demo


Hello I am the coin machine! I will give you the least number of coins for your change.
How many cents of change do you need? (Please enter from 1 to 99)
-10

You are welcome to give me money! Otherwise please enter a number from 1 to 99.

How many cents of change do you need? (Please enter from 1 to 99)
200

Sorry I can only give out less than 1 dollar of change.

How many cents of change do you need? (Please enter from 1 to 99)
86

86 cents can be given as:
3 Quarters
1 Dime
1 Penny

Want to get change again?
y

How many cents of change do you need? (Please enter from 1 to 99)
25

25 cents can be given as:
1 Quarter

Want to get change again?
n

Requirements


Your program will behave exactly as the Solution Demo above. 

If user input is invalid, prints appropriate message and ask them to enter another number (i.e. they do not need to confirm they want another chance)


Assume they will always input an integer, appropriate message for different types of invalid inputs will be different (e.g. when input < 0, input ==0, and input > 99).


Exact coins are output. Do not include the coin denomination if 0 of them is needed. For example, do not include something like 0 Dime.


Use correct singular and plural noun forms. For example, 3 Pennies and not 3 Penny.


Implement at least one function with pass-by-reference parameters.


Comments for all functions (including main()) will follow the format as shown in suggested functions compute_coins & output_coins.


Loop until user decided they want to stop the program.


Function Suggestions


Your program can use the following functions among others:


// ======================================================
// Function: compute_coins
// Purpose: calculate num (the number of coins of coin_value
// cents) from amount_left, update amount_left, and print
// out how many and which coin denomination the decreased
// amount is changed to.
// Assumptions:
// (1) coin_value is either 1, 10, or 25
// Parameters:
// (1) coin_value - coin denomiation value
// (2) num - maximum number of coins of denomination
// coin_value cents that can be obtained from amount_left
// (3) amount_left - how many cents are left to be changed
// Calls:
// output_coins
// ======================================================
void compute_coins(int coin_value, int& num, int& amount_left);

For example, suppose the value of the variable amount_left is 86 . Then, after the following call:


compute_coins(25, number, amount_left);

The value of number will be 3 and the value of amount_left will be 11 (because if you take 3 quarters from 86 cents, that leaves 11 cents). Hints: Use integer division and the % operator to implement the compute_coins function.


 


// ======================================================
// Function: output_coins
// Purpose: print out num followed by appropriate noun form
// of pennies, dimes, or quarters
// Assumptions:
// (1) coin_value is either 1, 10, or 25
// Parameters:
// (1) coin_value - coin denomiation value
// (2) num - number of coin_value coins
// ======================================================
void output_coins(int coin_value, int num);

For example:


output_coins(25, 3);

will output:


3 Quarters

1 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <vector>
using namespace std;

void compute_coins(int coin_value, int& num, int& amount_left);
void output_coins(int coin_value, int num);
int main() {
   //Declaring variables
int quarters,dimes,pennies,cents;
   char ch;
   cout<<"Hello I am the coin machine! I will give you the least number of coins for your change."<<endl;
  
   while(true)
   {
           while(true)
   {
   cout<<"How many cents of change do you need? (Please enter from 1 to 99)"<<endl;
   cin>> cents;

       if(cents<1)
       {
           cout<<"You are welcome to give me money! Otherwise please enter a number from 1 to 99."<<endl;
               }
               else if(cents>99)      
               {
                   cout<<"Sorry I can only give out less than 1 dollar of change."<<endl;
               }
               else
               break;
  
}
cout<<cents<<" cents can be given as:"<<endl;
       compute_coins(25,quarters,cents);
       compute_coins(10,dimes,cents);
       compute_coins(1,pennies,cents);
      
       output_coins(25,quarters);
       output_coins(10,dimes);
       output_coins(1,pennies);
      
       cout<<"Want to get change again?"<<endl;
       cin>>ch;
       if(ch!='Y' && ch!='y')
       {
           break;
       }
   }

  

  
      
      
      


   return 0;
}
void compute_coins(int coin_value, int& num, int& amount_left)
{
   num=amount_left/coin_value;
   amount_left=amount_left-(num*coin_value);
  
}
void output_coins(int coin_value, int num)
{
   if(coin_value==25 || coin_value==10 || coin_value==1)
   {
       if(coin_value==25)
       {
       if(num==1)
       {
           cout<<num<<" Quarter"<<endl;
       }
       else if(num>1)
       {
           cout<<num<<" Quarters"<<endl;
   }          
       }
       else if(coin_value==10)
       {
       if(num==1)
       {
           cout<<num<<" Dime"<<endl;
       }
       else if(num>1)
       {
           cout<<num<<" Dimes"<<endl;
   }          
       }
       else if(coin_value==1)
       {
                   if(num==1)
       {
           cout<<num<<" Penny"<<endl;
       }
       else if(num>1)
       {
           cout<<num<<" Pennies"<<endl;
   }
       }

   }
}

=====================================

output:

C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\CentsToQuarters DimesCents.exe Hello I am the coin machine! I will give you the le

=====================Could you plz rate me well.Thank You

C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\CentsToQuarters DimesCents.exe Hello I am the coin machine! I will give you the least number of coins for your change. How many cents of change do you need? (Please enter from 1 to 99) -10 You are welcome to give me money! Otherwise please enter a number from 1 to 99. How many cents of change do you need? (Please enter from 1 to 99) 200 Sorry I can only give out less than 1 dollar of change. How many cents of change do you need? (Please enter from 1 to 99), 86 3 Quarters 1 Dime 1 Penny Want to get change again? How many cents of change do you need? (Please enter from 1 to 99) 25 1 Quarter Want to get change again? Process exited after 29.78 seconds with return value o Press any key to continue ...

Add a comment
Know the answer?
Add Answer to:
Write a program that tells what coins to give out for as change from 1 cent...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • it c++ coding. please write on atom software. 1. Write a program that converts dollars into coins a. Request a dolla...

    it c++ coding. please write on atom software. 1. Write a program that converts dollars into coins a. Request a dollar amount as an integer: $5.34 is input as 534 b. Use a constant variable to represent each coin as a fixed value: const int NICKEL 5; c. Use division and the mod function to calculate the number of each coin. Change Calculator Enter dollar amount (as an integer): $534 The equivalent in coins: 21 Quarters 0 Dimes 1 Nickels...

  • (In Python 3) Write a program with total change amount as an integer input, and output...

    (In Python 3) Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 (or less than 0), the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes So...

  • Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10...

    Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10 quarters, and 10 pennies. 2. Repeatedly prompt the user for a price in the form xX.xx, where X denotes a digit, or to enter q' to quit 3. When a price is entered a. If the price entered is negative, print an error message and start over requesting either a new price or to quit (indicated by entering a 'q)...

  • I need to change this python program into one that counts back the LEAST AMOUNT OF...

    I need to change this python program into one that counts back the LEAST AMOUNT OF COINS. Ex: if i input 44 as my change, how can i make it show 4 dimes and 4 pennies instead of 1 quarter, a dime, and 9 pennies? heres my code so far in PYTHON " cents=int(input("Please enter the change in Cents: ")) Quarter= int(cents/25)#25cents=1 Quarter Dime =int (cents%25/10)# 10 cents=1 Dime cents =(cents%25)%10 print(Quarter,"quarters",Dime,"dimes and",cents,"cents") "

  • C++ Write a program that helps a young student learn to make change. Use the random...

    C++ Write a program that helps a young student learn to make change. Use the random number generator to generate change amounts between1¢ and 99¢. Ask the user how many quarters, dimes, nickels and pennies they need to make that amount. Determine whether the coins specified by the user total the specified amount and give them feedback on their answer including whether they used the minimum or optimum number of coins to produce the amount. Sample output of a program...

  • All items at a "Penny Fair" are priced less than $1.00. Write a program that makes...

    All items at a "Penny Fair" are priced less than $1.00. Write a program that makes change with a minimum number of coins when a customer pays for an item with a one dollar bill. Prompt for the item price in cents, report the change due, and the number of coins of each denomination required. Use only quarters, dimes, nickels, and pennies for change (no 50 cent pieces). See sample output but your program should work for any item price....

  • Write a program with total change amount as an integer input, and output the change using...

    Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes

  • write a PHP program makes change for a given number of cents. The program should ask...

    write a PHP program makes change for a given number of cents. The program should ask the user for the amount of cents and then output the change for specific denominations of ten dollar bills, five dollar bills, one dollar bills, quarters, dimes, nickels, and pennies. Here is a sample program output for an input of 265 cents: Change for 2 dollars and 65 cents : 0 ten dollar bills 0 five dollar bills 2 one dollar bills 2 quarters...

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

  • Write a C program that calculates exact change. In order to receive full credit, please remember...

    Write a C program that calculates exact change. In order to receive full credit, please remember that only int arithmetic is exact, so you’ll need to break up your double into two ints, the one before the decimal point and the one after the decimal point. Another point worth mentioning is that the % operator gives the remainder. In other words, when working with int values, 9 / 5 = 1 whereas 9 % 5 = 4. Keep this in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT