Question

I'm having trouble figuring out the C++ code for the following assignment, keep getting errors. Help?...

I'm having trouble figuring out the C++ code for the following assignment, keep getting errors. Help?

Write a program that calculates a discount for buying certain quantities of coffee. Consider the following scenario:

A coffee company sells a pound of coffee for $12.99. Quantity discounts are given according to the table below.

Quantity Discount
5-9 5%
10-19 10%
20-29 15%
30 or more 20%

Write a program that asks for the number of pounds purchased and computes the total cost of the purchase. Make sure the output formatting is appropriate for the values provided. Be sure to include comments throughout your code where appropriate.

Input validation: Decide how the program should handle an input of less than 0.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

int main()
{
    const double UNIT_PRICE = 12.99;
    int n;
    double totalPrice;
    
    cout<<"Enter quantity: ";
    cin>>n;
    
    if(n>0){
    
    totalPrice = n*UNIT_PRICE;
    if(n>5){
        if(n<9){
            totalPrice -= (totalPrice*5/100.0);
        }
        else if(n<20){
            totalPrice -= (totalPrice*10/100.0);
        }
        else if(n<30){
            totalPrice -= (totalPrice*15/100.0);
        }
        else{
            totalPrice -= (totalPrice*20/100.0);
        }
    }
    
    cout<<"Total price = "<<totalPrice<<endl;
    }
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
I'm having trouble figuring out the C++ code for the following assignment, keep getting errors. Help?...
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
  • Please solve the following in Python 3 only. Also, share code and show output. A software...

    Please solve the following in Python 3 only. Also, share code and show output. A software company sells a package that retails for $99. Quantity discounts are given according to the following table. Quantity Discount 10–19 20% 20–49 30% 50–99 40% 100 or more 50% Write a program that asks for the number of units sold and computes the total cost of the purchase. Input Validation: Make sure the number of units is greater than 0.

  • I'm kind of new to programming, and I am having trouble figuring out why my program...

    I'm kind of new to programming, and I am having trouble figuring out why my program isn't running. Below is the code that I wrote for practice. I will comment where it says the error is. So the error that I'm getting is "error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' ". I'm not sure why I'm getting this because I added the library <iostream> at the top. Thank you. Code: #include <iostream> using namespace std; class...

  • Code in c++ please Q1: Software Sales A software company sells a package that retails for...

    Code in c++ please Q1: Software Sales A software company sells a package that retails for $99. Quantity discounts are given according to the following table: QuantityDiscount 10-19 20-49 50-99 100 or more 20% 30% 40% 50% : Write a program that asks for the number of units sold and computes the total cost of the purchase. Input validation: Make sure the number of units is greater than 0. Q2: Book Club Points Community Booksellers has a book club that...

  • Computer science help! A software company sells their software packages for $99.00 each. They would like...

    Computer science help! A software company sells their software packages for $99.00 each. They would like you to write a program that will calculate and display an invoice for their customers. Quantity discounts are given according to the following table: Quantity   Discount 1 - 9 No discount 10 – 19 20% 20 – 49 30% 50 - 99 40% 100 or more 50% Write a C++ program that asks for the customer’s name and the number of software packages sold...

  • I'm having trouble writing this code, can some help me? Step 1: Capturing the input The...

    I'm having trouble writing this code, can some help me? Step 1: Capturing the input The first step is to write a functionGetInput()that inputs the expression from the keyboard and returns the tokens---the operands and operators---in a queue. You must write this function. To make the input easier to process, the operands and operators will be separated by one or more spaces, and the expression will be followed by #. For example, here’s a valid input to your program: 6...

  • So. I'm sick and I need help figuring out whatever is going on with this. #include...

    So. I'm sick and I need help figuring out whatever is going on with this. #include using namespace std; //prototypes int getExchangesInBubbleSort(int[], int); int getExchangesInSelectionSort(int[], int); int main() {    char choice;       cout << "1. Search Benchmarks\n";    cout << "2. Sorting Benchmarks\n";    do    {        int input;        cout << "Please enter the program you would like to run. \n";        cin >> input;               if (input == 1)...

  • I'm having trouble figuring out how to calculate the numbers that go into the NPV analysis...

    I'm having trouble figuring out how to calculate the numbers that go into the NPV analysis grids. The three values that I came up with in the first grid next to NPV in cells I'm not sure if it's correct. Can you help with both grids please? The questions below must be answered after. 2D. Based on your NPV Scenario / Risk Analysis Grids, is NPV more sensitive to changing cost of capital or changing salvage values? How do you...

  • This looks long but it is easy just having some trouble please help out thank you....

    This looks long but it is easy just having some trouble please help out thank you. Find and fix all syntax and semantic errors which prevent the program from compiling. Find and fix all logical errors which cause the program to crash and/or produce unexpected results. In addition to making sure the code compiles, we have one final method which we need to complete. There is a method in the code, printAll, which is responsible for printing out the entirety...

  • I need help figuring out how to code this in C++ in Visual Studio. Problem Statement:...

    I need help figuring out how to code this in C++ in Visual Studio. Problem Statement: Open the rule document for the game LCR Rules Dice Game. Develop the code, use commenting to describe your code and practice debugging if you run into errors. Submit source code. Use the document to write rules for the user on how to play the game in a text file. Then, using the information from the resource articles, create a program that will read...

  • I need help with this assignment in C++, please! *** The instructions and programming style detai...

    I need help with this assignment in C++, please! *** The instructions and programming style details are crucial for this assignment! Goal: Your assignment is to write a C+ program to read in a list of phone call records from a file, and output them in a more user-friendly format to the standard output (cout). In so doing, you will practice using the ifstream class, I'O manipulators, and the string class. File format: Here is an example of a file...

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