Question

HELP ( i get these comment for this assignment please help me to fixed Please do...

HELP ( i get these comment for this assignment please help me to fixed Please do not ask user to enter cents.  Amount due and received should be in dollars such as 2.35 and 5.)

Business P2.8Giving change. 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.

#include <iostream>

using namespace std;

int main()
{
int cents=0, dollars=0, quarters=0, dimes=0, nickels=0, pennies=0;
int due, received;

cout << "Enter amount due(in cents): ";
cin >> due;
cout << "Enter amount received(in cents): ";
cin >> received;

cents = received - due;

if (cents > 0)
{
   if (cents >= 100)
{
   dollars = cents / 100;
   cents = cents % 100;
}
       else if (cents < 100 && cents >= 25)
       {
       quarters = cents / 25;
       cents = cents % 25;
       }
       else if (cents <25 && cents >= 10)
       {
       dimes = cents / 10;
       cents = cents % 10;
       }
       else if (cents <10 && cents >= 5)
       {
       nickels = cents / 5;
       cents = cents % 5;
       }
       else if(cents <10 && cents > 0)
       {
       pennies = cents;
       }
       cout << "The number of dollars to be returned is " << dollars << endl;
       cout << "The number of quarters to be returned is " << quarters << endl;
       cout << "The number of dimes to be returned is " << dimes << endl;
       cout << "The number of nickels to be returned is " << nickels << endl;
       cout << "The number of pennies to be returned is " << pennies << endl;
       }
else
{
cout << "You still owe " << cents << " cents" << endl;
}

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

#include <iostream>

using namespace std;

int main()
{
int cents=0, dollars=0, quarters=0, dimes=0, nickels=0, pennies=0;
double due, received,remaining;

//reading amounts in dollors

cout << "Enter amount due: ";
cin >> due;
cout << "Enter amount received ";
cin >> received;

remaining = received - due;

//converting remaining amount to cents
cents=remaining*100;

if (cents > 0)
{
dollars=cents/100;
cents=cents%100;
  
quarters=cents/25;
cents=cents%25;
  
dimes=cents/10;
cents=cents%10;
  
nickels=cents/5;
cents=cents%5;
pennies=cents;

  
cout << "The number of dollars to be returned is " << dollars << endl;
cout << "The number of quarters to be returned is " << quarters << endl;
cout << "The number of dimes to be returned is " << dimes << endl;
cout << "The number of nickels to be returned is " << nickels << endl;
cout << "The number of pennies to be returned is " << pennies << endl;
}
else
{
cout << "You still owe " << cents << " cents" << endl;
}

return 0;
}

Add a comment
Know the answer?
Add Answer to:
HELP ( i get these comment for this assignment please help me to fixed Please do...
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, 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...

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

  • Hello. I am using Visual Studio 2019 and am not sure why it is telling me...

    Hello. I am using Visual Studio 2019 and am not sure why it is telling me I have 5 errors when I BUILD my code in C++. Can someone please take a look? #include using namespace std; int main() { int number_of_quarters, total_value_of_quarters; int number_of_dimes, total_value_of_dimes; int number_of_nickels, total_value_of_nickels; int number_of_pennies, total_value_of_pennies; int total_value_of_coins, total_dollars, total_cents; cout<<"Please enter the # of quarters: "<>number_of_quarters; cout<<"Please enter the # of dimes: "<>number_of_dimes; cout<<"Please enter the # of nickels: "<>number_of_nickels; cout<<"Please enter the...

  • Construct a program in C++ that exchanges coins for cash like Coinstar that is located in...

    Construct a program in C++ that exchanges coins for cash like Coinstar that is located in several grocery stores. You will prompt the user to provide you with the total number of pennies, nickels, dimes, and quarters, respectively.   You are to determine the total amount of money entered by the user and then output the cash that should be received. For example, if a user enters 50 pennies, 10 dimes, 10 nickels, and 5 quarters, then the user would receive...

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

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

  • C Program that prompts the user to enter a number that represents a pile of pennies....

    C Program that prompts the user to enter a number that represents a pile of pennies. Then, the program should use that input value to distribute the cents over monetary denominations of dollars, half dollars, quarters, dimes, nickels and pennies. Distribute the pennies over the other denominations with Change function :    prototype: void Change(int *dollars, int *halfDollars, int *quarters, int *dimes, int *nickels, int *pennies); The function takes a logical input value via its pennies parameter that represents the total...

  • I have this code for python: num = int(input()) if num == 0: print('No change') else:...

    I have this code for python: num = int(input()) if num == 0: print('No change') else: dol = num // 100 num %= 100 Quarters = num // 25 num %= 25 Dimes = num // 10 num %= 10 Nickels = num // 5 num %= 5 Pennies = num if dol > 0: if dol == 1: print('1 Dollar') if Dollars > 1: print(dol,'Dollars') if Quarters > 0: if Quarters == 1: print('1 Quarter') if Quarters > 1:...

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

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

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