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

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 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...
How can we write an application that calculates connascence of an application?
How can we write an application that calculates connascence of an application?
Please use Phyton to write a program: Write a program that calculates and displays the total...
Please use Phyton to write a program: Write a program that calculates and displays the total bill at a restaurant for a couple that is dining. The program should collect from the couple, cost of each meal, and the percentage of the final cost that they would like to tip. The sales tax in the state where the restaurant exists is 7.5%. Display to the user, line by line: Total Cost of Both Meals Sales Tax in dollars Tip in...
Write a program named MakeChange that calculates and displays the conversion of an entered number of...
Write a program named MakeChange that calculates and displays the conversion of an entered number of dollars into currency denominations—twenties, tens, fives, and ones. For example, if 113 dollars is entered, the output would be twenties: 5 tens: 1 fives: 0 ones: 3. Answer in C# (P.S i'm posting the incomplete code that i have so far below.) using System; using static System.Console; class MakeChange { static void Main() { int twenties, tens, fives, ones; WriteLine("Enter the number of dollars:");...
C# I need working code please Write a console application that accepts the following JSON as...
C# I need working code please Write a console application that accepts the following JSON as input: {"menu": { "header": "SVG Viewer", "items": [ {"id": "Open"}, {"id": "OpenNew", "label": "Open New"}, null, {"id": "ZoomIn", "label": "Zoom In"}, {"id": "ZoomOut", "label": "Zoom Out"}, {"id": "OriginalView", "label": "Original View"}, null, {"id": "Quality"}, {"id": "Pause"}, {"id": "Mute"}, null, {"id": "Find", "label": "Find..."}, {"id": "FindAgain", "label": "Find Again"}, {"id": "Copy"}, {"id": "CopyAgain", "label": "Copy Again"}, {"id": "CopySVG", "label": "Copy SVG"}, {"id": "ViewSVG", "label": "View...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT