Question

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 that satisfies the requirements is shown below. The data entered by the user is in blue.

Sample Output 1: What coins are needed to make $0.39? Quarters? 1 Dimes? 1 Nickels? O Pennies? 4 Excellent that is correct! S

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

Answer:

Explanation:

First using rand() function, random number is generated for coins variable, then it is copied to tem for future use as the coins variable will be modified.

Then, asking the user given values for quarters, dimes, nickles and pennies and storing in a, b, c and d.

Then, the actual solution is calculated and stored in quarters, dimes, nickles, and pennies variables.

Then using if else block, the values of user are added and if those coins give a value of temp. Answer is correct. If it does not matches with the optimum solution, optimum solution is printed.

In the else block, it is printed that the answer is wrong and the solution is also printed.

Code:


#include <iostream>
#include <stdlib.h>
using namespace std;

int main()
{
srand(time(0));
  
int coins = rand()%99 + 1;
int temp = coins;
cout<<"What coins are needed to make $0."<<coins<<"?"<<endl<<endl;
int a, b, c, d;
cout<<"Quarters? ";
cin>>a;
cout<<"Dimes? ";
cin>>b;
cout<<"Nickles? ";
cin>>c;
cout<<"Pennies? ";
cin>>d;
  
int quarters = coins/25;
  
coins = coins%25;
  
int dimes = coins/10;
  
coins = coins%10;
  
int nickles = coins/5;

coins = coins%5;
  
int pennies = coins/1;
  

if(((a*25) + (b*10) + (c*5) + (d*1))==temp)
{
cout<<"Excellent that is correct!"<<endl;
  
if(a!=quarters || b!=dimes || c!=nickles || d!=pennies)
{
cout<<"The optimum solution is:"<<endl;
}
}
else
{
cout<<"That is not correct!"<<endl;
cout<<"The solution is: "<<endl;
  
}
  
cout<<"\tQuarters: "<<quarters<<endl;
cout<<"\tDimes: "<<dimes<<endl;
cout<<"\tNickles: "<<nickles<<endl;
cout<<"\tPennies: "<<pennies<<endl;
return 0;
}

Output:

What coins are needed to make $0.85? Quarters? 3 Dimes? O Nickles? 2 Pennies? O Excellent that is correct! The optimum soluti

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

Add a comment
Know the answer?
Add Answer to:
C++ Write a program that helps a young student learn to make change. Use the random...
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
  • (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...

  • Problem: Implement (in C) the dynamic program algorithm for the coin-change algorithm, discussed in class. Assume...

    Problem: Implement (in C) the dynamic program algorithm for the coin-change algorithm, discussed in class. Assume that the coins with which you make change are quarters, dimes, nickels and pennies. Thus you are going to set n = 4 in your program. The amount k for which you have to make change will be provided by the user and your program will return the minimum number of coins needed and also the break-up of the change in terms of the...

  • 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...

  • 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

  • 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....

  • In Python 3, Implement a program that directs a cashier how to give change. The program...

    In Python 3, Implement a program that directs a cashier how to give change. The program has two inputs: the amount due and the amount received from the customer. Display the dollars, quarters, dimes, nickels, and pennies that the customer should receive in return. In order to avoid roundoff errors, the program user should supply both amounts in pennies, for example 526 instead of 5.26. Enter the amount due in pennies: 828 Enter the amount received from the customer in...

  • PLease help!!! how to type them in Python !!!! Python help!! THank you so much Problem...

    PLease help!!! how to type them in Python !!!! Python help!! THank you so much Problem 1: (20 points) Optimal change You will write a program that uses the // and % operators to figure out how to give change for a specified amount using the minimum number of coins (quarters, dimes, nickels, cents). The good news is that our currency is specifically designed to make this problem easy. For a given number of cents, first use as many quarters...

  • 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...

  • I made this C program to count change and make a slip saying the exact dollar...

    I made this C program to count change and make a slip saying the exact dollar and change amount given. every time I run the program it says the change given is 477256577 and i'm not sure what I have done wrong? #include<stdio.h> int main(void) { char first, last; int pennies; int nickels; int dimes; int quarters; int loonies; int change; int t_dollars; int t_cents; printf("Type in your 2 initials and press return> "); scanf("%c%c",&first,&last); printf("%c%c please enter in your...

  • 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...

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