In: Computer Science
Remember that great app you wrote for Yogurt Yummies (Lab 10-2). They want you to enhance the C++ console application that calculates and displays the cost of a customer’s yogurt purchase. Now they need to process multiple sales. Do not change any logic for handling a single sale. Make the following enhancements:
● Add "v2" to the application output header and close.
● Declare and initialize overall totals including:
ü Number of sales.
ü Overall number of yogurts sold.
ü Overall sale amount after discount.
ü Overall tax paid.
ü Overall sale total.
● Enclose the logic for a single sale with a sentinel loop that continues to process sales until the user enters 'n'.
● After calculating sale totals, update overall totals.
● When the user enters the sentinel value ('n'), print overall totals using formatted output manipulators (setw, left/right). Run the program with invalid and valid inputs, and at least three sales. The output should look like this:
Welcome to Yogurt Yummies, v2
-----------------------------
Enter another yogurt purchase (y/n)? y
Sale 1
----------------------------------------
Enter the number of yogurts purchased (1-9): 11
Error: '11' is an invalid number of yogurts.
Enter the number of yogurts purchased (1-9): 2
Enter the percentage discount (0-20): 22
Error: '22.00' is an invalid percentage discount.
Enter the percentage discount (0-20): 4
Yogurts: 2
Yogurt cost ($): 3.50
Discount (%): 4.00
Subtotal ($): 7.00
Total after discount ($): 6.72
Tax ($): 0.40
Total ($): 7.12
Enter another yogurt purchase (y/n)? y
Sale 2
----------------------------------------
Enter the number of yogurts purchased (1-9): 5
Enter the percentage discount (0-20): 10
Yogurts: 5
Yogurt cost ($): 3.50
Discount (%): 10.00
Subtotal ($): 17.50
Total after discount ($): 15.75
Tax ($): 0.94
Total ($): 16.70
Enter another yogurt purchase (y/n)? y
Sale 3
----------------------------------------
Enter the number of yogurts purchased (1-9): 7
Enter the percentage discount (0-20): 20
Yogurts: 7
Yogurt cost ($): 3.50
Discount (%): 20.00
Subtotal ($): 24.50
Total after discount ($): 19.60
Tax ($): 1.18
Total ($): 20.78
Enter another yogurt purchase (y/n)? n
Overall totals
========================================
Sales: 3
Yogurts: 14
Total after discount ($): 42.07
Tax ($): 2.52
Total ($): 44.59
End of Yogurt Yummies, v2
This is from yogurt Yummies V1
Welcome to Yogurt Yummies
-------------------------
Enter the number of yogurts purchased (1-9): 12
Error: '12' is an invalid number of yogurts.
Enter the number of yogurts purchased (1-9): 4
Enter the percentage discount (0-20): 30
Error: '30.00' is an invalid percentage discount.
Enter the percentage discount (0-20): 10
Yogurts: 4
Yogurt cost ($): 3.50
Discount (%): 10.00
Subtotal ($): 14.00
Total after discount ($): 12.60
Tax ($): 0.76
Total ($): 13.36
End of Yogurt Yummies
PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU
#include <iostream>
#include <iomanip>
#define COST 3.50
#define TAX 0.06
using namespace std;
// Function to accept number of yogurts from the user and validates
// returns the number of yogurts by using pass by reference
void acceptNumberOfYogurts(int &numberOfYogurts)
{
// Loops till valid number of yogurts entered by the user
do
{
// Accepts number of yogurts
cout << "\n Enter the number of yogurts purchased (1-9): ";
cin >> numberOfYogurts;
// Checks if number of yogurts is greater than or equals to 1
// and number of yogurts is less than or equals to 9
if (numberOfYogurts >= 1 && numberOfYogurts <= 9)
// Come out of the loop for valid data
break;
// Otherwise invalid data display error message
else
cout << "\n Error: \'" << numberOfYogurts << "\' is an invalid number of yogurts.";
} while (1); // End of do - whil loop
} // End of function
// Function to accept percentage discount from the user and validates
// returns the percentage discount by using pass by reference
void acceptPercentageDiscount(double &percentageDiscount)
{
// Loops till valid percentage discount entered by the user
do
{
// Accepts percentage discount
cout << "\n Enter the percentage discount (0 - 20): ";
cin >> percentageDiscount;
// Checks if percentage discount is greater than or equals to 0
// and percentage discount is less than or equals to 20
if (percentageDiscount >= 0 && percentageDiscount <= 20)
// Come out of the loop for valid data
break;
// Otherwise invalid data display error message
else
cout << "\n Error: \'" << percentageDiscount << "\' is an invalid percentage discount.";
} while (1); // End of do - whil loop
} // End of function
// main function definition
int main()
{
int numberOfYogurtsPurchased;
double percentageDiscount;
int countSales = 0;
int totalYogurts = 0;
double subTotal = 0.0;
double afterDiscount = 0.0;
double tax = 0.0;
double total = 0.0;
double totalAfterDiscount = 0.0;
double totalTax = 0.0;
double overalTotal = 0.0;
char choice;
cout<<"Welcome to Yogurt Yummies, v2\n-----------------------------\n";
// Loops till user choice is not equals to 'n' or 'N'
do
{
// Accepts user choice
cout << "\n Enter another yogurt purchase (y/n)? ";
cin >> choice;
// Checks if user choice is equals to 'n' or 'N' then come out of the loop
if (choice == 'n' || choice == 'N')
break;
// Displays sales counter
cout << "\n Sales: " << ++countSales;
cout << "\n ----------------------------------------";
// Calls the function to accept number of yogurts purchased
acceptNumberOfYogurts(numberOfYogurtsPurchased);
// Calls the function to accept percentage discount
acceptPercentageDiscount(percentageDiscount);
// Calculates to total number of yogurts purchased
totalYogurts += numberOfYogurtsPurchased;
// Calculates sub total by multiplying number of yogurts purchased with cost per of yogurts purchased
subTotal = numberOfYogurtsPurchased * COST;
// Calculate amount after discount
afterDiscount = subTotal - (subTotal * percentageDiscount) / 100.0;
// Calculates tax
tax = (afterDiscount * TAX);
// Calculates total
total = afterDiscount + tax;
// Displays current purchase report
cout << left << setw(28) << "\n Yogurts: " << right << numberOfYogurtsPurchased;
cout << left << setw(28) << "\n Yogurt cost ($): " << right << fixed << setprecision(2) << COST;
cout << left << setw(28) << "\n Discount (%): " << right << percentageDiscount;
cout << left << setw(28) << "\n Subtotal ($): " << right << subTotal;
cout << left << setw(28) << "\n Total after discount ($): " << right << afterDiscount;
cout << left << setw(28) << "\n Tax ($): " << right << tax;
cout << left << setw(28) << "\n Total ($): " << right << total;
// Calculates total of after discount
totalAfterDiscount += afterDiscount;
// Calculates total tax
totalTax += tax;
// Calculates overall total
overalTotal += total;
} while (1); // End of do - while loop
// Displays overall report
cout << "\n Overall totals";
cout << "\n ========================================";
cout << left << setw(28) << "\n Sales: " << right << countSales;
cout << left << setw(28) << "\n Yogurts: " << right << totalYogurts;
cout << left << setw(28) << "\n Total after discount ($): " << right << totalAfterDiscount;
cout << left << setw(28) << "\n Tax ($): " << right << setprecision(2) << totalTax;
cout << left << setw(28) << "\n Total ($): " << right << setprecision(2) << overalTotal;
return 0;
} // End of function