Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A fireworks stand sells repeating fireworks for the following prices: 1-5 items,

ID: 3849887 • Letter: A

Question

A fireworks stand sells repeating fireworks for the following prices:

1-5 items, $19.99 each

5-10 items, $17.50 each

over 10 items, $14.99 each

Write a program that will ask the user how many items they are purchasing, calculate the cost, calculate the sales tax at 7.5% of the total cost and print a receipt to the monitor showing the number of items purchased, the cost before tax, the tax, and the total cost with tax.

Use separate functions to:

·         Read the number of items from the user

·         Calculate the cost before tax

·         Calculate the tax

·         Print the receipt

Input Validation: Make sure the number of items is greater than 0, if not, print an error message and exit the program.

Please use comments to explain functions used.

Explanation / Answer

c++ code:

#include <bits/stdc++.h>
using namespace std;

int input()
{
    cout << "Please enter the number of items you want to purchase! ";
    int n ;
    cin >> n;
    if(n <= 0)
    {
        cout << "Number of items must be positive integer!";
        exit(0);
    }
    return n;
}

float cost_before_tax(int n)
{
    if(1 <= n and n <= 5)
    {
        return 19.99*n ;
    }
    else if(5 < n and n <=10)
    {
        return 17.5*n;       
    }
    else
    {
        return 14.99*n;       
    }
}

float tax(float cost)
{
    return cost*0.075;
}

void reciept(int n, float costbt, float taxx)
{
    cout << "Number of items = " << n << endl;
    cout << "Cost before tax = $" << costbt << endl;
    cout << "Tax= $ " << taxx << endl;
    cout << "cost_after_tax = $" << costbt + taxx << endl;
}
int main()
{
    int n_items = input();
    float costbt = cost_before_tax(n_items);
    float taxx = tax(costbt);
    reciept(n_items,costbt,taxx);
    return 0;
}

Sample Output:

Please enter the number of items you want to purchase!
10
Number of items = 10
Cost before tax = $175
Tax= $ 13.125
cost_after_tax = $188.125

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote