Question

In C++ Consider a cash register that uses an automated machine. For the “paper money inserted”,...

In C++

Consider a cash register that uses an automated machine.
For the “paper money inserted”, and the “amount of purchase”,
the machine returns “paper money and coins”.
Write a program that gets from user the following “paper money
inserted” and the “amount of purchase”, and display the output as:

Purchase 3.08
Payment 10.00
Change 6.92
Dollars 6
Quarters 3
Dimes 1
Nickels 1
Pennies 2

Hint:
- to get “dollars” and “coins” use : static_cast < int >
- use ‘fixed’ and ‘setprecision(2)’ as initial global
input to ‘cout’, to be automatically used for all displays that
follow;
- insert: <<left << setw(8)) for displaying a left field;
- insert: << right << setw(8) for displaying a right field.
- setw() is not sticky; insert it for every new display !

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

Explanation::

  • Code in C++ is given below
  • Screenshot of the OUTPUT is given at the end of the code


Code in C++::

#include<iostream>
#include<iomanip>
using namespace std;
int main(){
/**
* Two float variables are declared to store paper money
* inserted and the amount of purchase named paperMoney and
* amountPurchase
*/
float paperMoney,amountPurchase;

/**
* Prompting user to enter the amount of purchase i.e amountPurchase
*/
cout<<"Enter amount of purchase : ";
cin>>amountPurchase;

/**
* Prompting user to enter paper money inserted i.e paperMoney
*/
cout<<"Enter paper money inserted : ";
cin>>paperMoney;

/**
* Now another float variable named change is declared below
*/
float change=paperMoney-amountPurchase;

int dollars=static_cast<int>(change);
int coins=100*(change-static_cast<long long>(change));

int quarters=coins/25;
coins=coins%25;

int dimes=coins/10;
coins=coins%10;

int nickels=coins/5;
coins=coins%5;

int pennies=coins;

/**
* Printing the values
*/

cout<<setw(8)<<left;
cout<<"Purchase";
cout<<setw(8)<<right;
cout<<setprecision(2)<<fixed<<amountPurchase<<endl;

cout<<setw(8)<<left;
cout<<"Payment";
cout<<setw(8)<<right;
cout<<setprecision(2)<<fixed<<paperMoney<<endl;

cout<<setw(8)<<left;
cout<<"Change";
cout<<setw(8)<<right;
cout<<setprecision(2)<<fixed<<change<<endl;

cout<<setw(8)<<left;
cout<<"Dollars";
cout<<setw(8)<<right;
cout<<dollars<<endl;

cout<<setw(8)<<left;
cout<<"Quarters";
cout<<setw(8)<<right;
cout<<quarters<<endl;

cout<<setw(8)<<left;
cout<<"Dimes";
cout<<setw(8)<<right;
cout<<dimes<<endl;

cout<<setw(8)<<left;
cout<<"Nickels";
cout<<setw(8)<<right;
cout<<nickels<<endl;

cout<<setw(8)<<left;
cout<<"Pennies";
cout<<setw(8)<<right;
cout<<pennies<<endl;

return 0;
}

OUTPUT::

Please provide the feedback!!

Thank You!!


Add a comment
Know the answer?
Add Answer to:
In C++ Consider a cash register that uses an automated machine. For the “paper money inserted”,...
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
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