Part 3 And now for the fun part, the challenge. This challenge is asking you to
ID: 3755968 • Letter: P
Question
Part 3 And now for the fun part, the challenge. This challenge is asking you to write a program that will simulate a cash register.Ask for the price of an item, the payment amount from the customer, and then print out the change due to the customer but print it out as dollars, the number of quarters, the number of dimes, the number of nickels, and the number of pennies. Hint, this is a good opportunity to work with modules or remainder division. Also allow the user to enter multiple transactions. You have 1 hour and a half to complete this task, so take your time and have fun. After you write the program and test it try to write an explanation to tell us how did you solve your problem, using your own words.Explanation / Answer
#include<iostream>
using namespace std;
// main function definition
int main()
{
double price, paid, moneyChange, c_money, quarters, dimes, nickels, pennies, remainder;
char choice;
// Loops till user choice is not 'N' or 'n'
do
{
// Loops till valid price entered by the user
do
{
// Accepts price
cout << " Enter the product price: " << endl;
cin >> price;
// Checks if price is less than or equals to 0
// Display error message
if(price <= 0)
cout<<" Invalid product price. Try again.";
// Otherwise valid price, come out of the loop
else
break;
}while(1); // End of do while loop
// Loops till valid purchased price entered by the user
do
{
// Accepts price
cout << " Enter the amount paid by the customer: " << endl;
cin >> paid;
// Checks if price is less than or equals to 0
// Display error message
if(paid <= 0)
cout<<" Invalid paid price. Try again.";
// Otherwise valid price, come out of the loop
else
break;
}while(1); // End of do while loop
// Calculate difference amount
moneyChange = paid - price;
cout<<" change: "<<moneyChange;
// Calculate the conversion mechanism
c_money = moneyChange * 100;
quarters = (int)c_money / 25;
remainder = (int)c_money % 25;
dimes = (int)remainder / 10;
remainder = (int)remainder % 10;
nickels = (int)remainder /5;
remainder = (int)remainder % 5;
pennies = (int)remainder ;
cout << endl;
// Displays the result
cout << " The money needs to refund: " << endl;
cout << "*****************************************************" << endl;
cout <<" Number of quarters : "<< quarters << endl;
cout <<" Number of dimes : "<<dimes << endl;
cout <<" Number of nickels : "<< nickels << endl;
cout <<" Number of pennies : "<< pennies << endl<<endl;
// Accepts user choice to continue or not
cout << " Do you want more transaction?? (Y/N)" << endl;
cin >> choice;
// Checks if the choice is 'N' of 'n' then stop
if (choice == 'N' || choice == 'n')
break;
}while(1); // End of do while loop
cout << " Thanks for visit again!! ";
return 0;
}// End of main function
Sample Output:
Enter the product price:
200.12
Enter the amount paid by the customer:
500.90
change: 300.78
The money needs to refund:
*****************************************************
Number of quarters : 1203
Number of dimes : 0
Number of nickels : 0
Number of pennies : 2
Do you want more transaction?? (Y/N)
y
Enter the product price:
-12.56
Invalid product price. Try again.
Enter the product price:
12.56
Enter the amount paid by the customer:
-10.23
Invalid paid price. Try again.
Enter the amount paid by the customer:
100.10
change: 87.54
The money needs to refund:
*****************************************************
Number of quarters : 350
Number of dimes : 0
Number of nickels : 0
Number of pennies : 4
Do you want more transaction?? (Y/N)
n
Thanks for visit again!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.