Question

In: Computer Science

You've been hired by Yogurt Yummies to write a C++ console application that calculates and displays...

You've been hired by Yogurt Yummies to write a C++ console application that calculates and displays the cost of a customer’s yogurt purchase. Use a validation loop to prompt for and get from the user the number of yogurts purchased in the range 1-9. Then use a validation loop to prompt for and get from the user the coupon discount in the range 0-20%. Calculate the following:

        ● Subtotal using a cost of $3.50 per yogurt.

        ● Subtotal after discount

        ● Sale tax using rate of 6%.

        ● Total

Use formatted output manipulators (setw, left/right) to print the following rows:

        ● Yogurts purchased

        ● Yogurt cost ($)

        ● Discount (%)

        ● Subtotal ($)

        ● Subtotal after discount ($)

        ● Tax ($)

        ● Total ($)

And two columns:

        ● A left-justified label (including units)

        ● A right-justified value.

Define constants for the yogurt cost, sales tax rate, and column widths. Format all real numbers to two decimal places. Run the program with invalid and valid inputs. The output should look like this:

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

Solutions

Expert Solution

main.cpp

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
int n;
double discount, cost=3.50, tax=6;
  
cout<<"Welcome to Yogurt Yummies"<<endl;
cout<<"-------------------------"<<endl;
  
do{
cout<<"Enter the number of yogurts purchased (1-9): ";
cin>>n;
if(n<1 || n>9)
cout<<"Error: '"<<n<<"' is an invalid number of yogurts."<<endl;
}while(n<1 || n>9);
  
do{
cout<<"Enter the percentage discount (0-20): ";
cin>>discount;
if(discount<0 || discount>20)
cout<<"Error: '"<<discount<<"' is an invalid percentage discount."<<endl;
}while(discount<0 || discount>20);
  
double subtotal = n*cost;
double total_after_discount = subtotal - (subtotal*discount/100);
double total_tax = total_after_discount*tax/100;
double total = total_after_discount+total_tax;
  
cout<<fixed<<setprecision(2);
cout<<"Yogurts: \t"<<n<<endl;
cout<<"Yogurt cost ($): \t"<<cost<<endl;
cout<<"Discount (%): \t"<<discount<<endl;
cout<<"Subtotal ($): \t"<<subtotal<<endl;
cout<<"Total after discount ($): \t"<<total_after_discount<<endl;
cout<<"Tax ($): \t"<<total_tax<<endl;
cout<<"Total ($): \t"<<total<<endl;
cout<<"End of Yogurt Yummies"<<endl;
  
return 0;
}

Code Snippet (For Indentation):

Output:


Related Solutions

Lab 10-2:You've been hired by Yogurt Yummies to write a C++ console application that calculates and...
Lab 10-2:You've been hired by Yogurt Yummies to write a C++ console application that calculates and displays the cost of a customer’s yogurt purchase. Use a validation loop to prompt for and get from the user the number of yogurts purchased in the range 1-9. Then use a validation loop to prompt for and get from the user the coupon discount in the range 0-20%. Calculate the following:           ● Subtotal using a cost of $3.50 per yogurt. ● Subtotal...
You've been hired by Avuncular Addresses to write a C++ console application that analyzes and checks...
You've been hired by Avuncular Addresses to write a C++ console application that analyzes and checks a postal address. Prompt for and get from the user an address. Use function getline so that the address can contain spaces. Loop through the address and count the following types of characters:         ● Digits (0-9)         ● Alphabetic (A-Z, a-z)         ● Other Use function length to control the loop. Use functions isdigit and isalpha to determine the character types. Use formatted...
You've been hired by Water Wonders to write a C++ console application that analyzes lake level...
You've been hired by Water Wonders to write a C++ console application that analyzes lake level data. MichiganHuronLakeLevels.txt. Place the input file in a folder where your development tool can locate it (on Visual Studio, in folder \). The input file may be placed in any folder but a path must be specified to locate it. MichiganHuronLakeLevels.txt Down below: Lake Michigan and Lake Huron - Average lake levels - 1860-2015 Year    Average level (meters) 1860    177.3351667 1861    177.3318333 1862    177.316...
You've been hired by Water Wonders to write a C++ console application that analyzes lake level...
You've been hired by Water Wonders to write a C++ console application that analyzes lake level data. Place the input file in a folder where your development tool can locate it (on Visual Studio, in folder <project-name>\<project-name>). The input file may be placed in any folder but a path must be specified to locate it. The input file has 158 lines and looks like this: Lake Michigan and Lake Huron - Average lake levels - 1860-2015 Year    Average level (meters)...
In C# Create a GUI application that calculates and displays the total travel expenses of a...
In C# Create a GUI application that calculates and displays the total travel expenses of a business person on a trip. Here is the information that the user must provide: Number of days on the trip Amount of airfare, if any Amount of car rental fees, if any Number of miles driven, if a private vehicle was used Amount of parking fees, if any Amount of taxi charges, if any Conference or seminar registration fees, if any Lodging charges, per...
Create a GUI application in C# that calculates and displays the total travel expenses of a...
Create a GUI application in C# that calculates and displays the total travel expenses of a business person on a trip. Here is the information that the user must provide: • Number of days on the trip • Amount of airfare, if any • Amount of car rental fees, if any • Number of miles driven, if a private vehicle was used • Amount of parking fees, if any • Amount of taxi charges, if any • Conference or seminar...
Create a C# Windows Console application that displays the following patterns separately, one after the other....
Create a C# Windows Console application that displays the following patterns separately, one after the other. You MUST use nested for loops to generate the patterns. All asterisks (*) should be displayed by a single statement of the form Console.Write("*"); which causes the asterisks to display side by side. A statement of the form Console.WriteLine(); can be used to move to the next line. A statement of the form Console.Write(" "); can be used to display a space for the...
Create an application that calculates and displays the amount of a homeowner’s property tax. The tax...
Create an application that calculates and displays the amount of a homeowner’s property tax. The tax is 1.35% of the property’s assessed value, which will be entered by the user. a. Prepare a Planning Chart for the application. b. Draw a sketch of an appropriate interface. Be sure to follow the GUI design guidelines covered in the chapter. The guidelines are summarized in Figure 2-20. (If you want to include an image in the interface, you can either use your...
write a c# console application app that reads all the services in the task manager and...
write a c# console application app that reads all the services in the task manager and automatically saves what was read in a Notepad txt file.  Please make sure that this program runs, also add some comments
write a c++ code for following application You have been hired by XYZ Car Rental to...
write a c++ code for following application You have been hired by XYZ Car Rental to develop a software system for their business. Your program will have two unordered lists, one of Cars and one of Reservations. The Car class will have the following data: string plateNumber (this is the key) string make string model enum vehicleType (VehicleType Enumeration of options: sedan, suv, exotic) double pricePerDay bool isAvailable isAvailable should be set to true on initialization, and a public setter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT