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

/* This program computes the amount of tax on two items and the total cost inclu

ID: 3714810 • Letter: #

Question

/*

           This program computes the amount of tax on two items and the total cost

            including tax of the two items given the cost of the items and the tax rate.

            Written by:    Your name here

            Date:               Current date here

*/

double compute_tax (double item1_cost, double item2_cost, double tax_rate);

#include <cstdlib>

#include <iostream>

#include <iomanip>

using namespace std;

int main( )

{

            double item1_cost;     // cost of the first item entered by the user

            double item2_cost; // cost of the second item entered by the user

            double tax_rate;        // percent tax rate

            double tax;                     // tax on the given item

            double total_cost; // cost of item plus tax

            cout << "Enter the cost of item 1:     $";

            cin >> item1_cost;

            cout << "Enter the cost of item 2:     $";

            cin >> item2_cost;

            cout << "Enter the tax rate (percent): ";

            cin >> tax_rate;

            // call to your function here

            total_cost = item1_cost + item2_cost + tax;

           

            cout << showpoint << fixed << setprecision (2);

            cout << " The tax on your items is:       $" << tax;

            cout << " The total cost of the items is: $" << total_cost << " ";

    return 0;

}

// define the compute_tax function definition here

// compute_tax returns the tax on the sum of the items given the cost of

// the two items and the tax rate as parameters.

Write a call to the function compute_tax in the main program where indicated (refer to the prototype for the proper return value and parameters). The return value should be placed in the variable tax.

Write the compute_tax function definition where indicated. Your program should compile and run when done.

Explanation / Answer


#include <cstdlib>

#include <iostream>

#include <iomanip>

using namespace std;
double compute_tax (double item1_cost, double item2_cost, double tax_rate);

int main( )

{

double item1_cost; // cost of the first item entered by the user

double item2_cost; // cost of the second item entered by the user

double tax_rate; // percent tax rate

double tax; // tax on the given item

double total_cost; // cost of item plus tax

cout << "Enter the cost of item 1: $";

cin >> item1_cost;

cout << "Enter the cost of item 2: $";

cin >> item2_cost;

cout << "Enter the tax rate (percent): ";

cin >> tax_rate;

// call to your function here
tax = compute_tax(item1_cost, item2_cost, tax_rate);

total_cost = item1_cost + item2_cost + tax;

cout << showpoint << fixed << setprecision (2);

cout << " The tax on your items is: $" << tax;

cout << " The total cost of the items is: $" << total_cost << " ";

return 0;

}

// define the compute_tax function definition here

// compute_tax returns the tax on the sum of the items given the cost of  

// the two items and the tax rate as parameters.
double compute_tax (double item1_cost, double item2_cost, double tax_rate) {
return ((item1_cost+item2_cost) * tax_rate)/100;
}

Output:

Enter the cost of item 1: $Enter the cost of item 2: $Enter the tax rate (percent):
The tax on your items is: $48.00
The total cost of the items is: $448.00