Question

In: Computer Science

Write a program to determine the shipping costs for an online purchase.

C++

13.2 Lab13 - using if-else if to calculate sales tax and shipping costs

The Concept

Real world problems often involve complex logical conditions. Today we learned two techniques to deal with complexity – the else if construct and logical operators. Use these new tools to below (really you only need one of these tools).

The Exercise

Write a program to determine the shipping costs for an online purchase.

  1. Prompt the user for the number of items using the following prompt:
    Enter the number of items:

  2. Prompt the user for the purchase price of using the following prompt:
    Enter the purchase price: $

  3. Calculate the sales tax as 8.25% of the purchase price

  4. Calculate the shipping costs as a flat rate using the following information:

    Number of itemsShipping cost
    1-6$8.00
    7-12$4.50
    more than 12$1.00
  5. Calculate the total cost as the sum of the purchase price, sales tax and shipping cost

  6. Output the sales tax and shipping costs using the following example:
    Purchase price: $##.##
    Sales tax: $##.##
    Shipping cost: $##.##
    Total cost: $##.##

Note: To format the output for 2 decimals use the following include statement:
#include
and prior to the output statements include the following statement:
cout << fixed << setprecision(2);

Examples:

Enter the number of items: 21
Enter the purchase price: $49.99
Purchase price: $49.99
Sales tax: $4.12
Shipping cost: $1.00
Total cost: $55.11
Enter the number of items: 10
Enter the purchase price: $35.00
Purchase price: $35.00
Sales tax: $2.89
Shipping cost: $4.50
Total cost: $42.39

Solutions

Expert Solution

#include
#include

using namespace std;

int main()
{
int n;
cout<<"Enter the number of items: ";
cin>>n;
float purchase_price;
cout<<"Enter the purchase price: $";
cin>>purchase_price;
float sales_tax = (825*purchase_price)/10000;
  
float shipping_price;
  
if(n>=1 && n<=6)
shipping_price = 8.00;
else if(n>=7 && n<=12)
shipping_price = 4.50;
else if(n>12)
shipping_price = 1.00;
  
float total_price = purchase_price + sales_tax + shipping_price;
  
cout<<"Purchase price: $"< cout<<"Sales tax: $"< cout<<"Shipping cost: $"< cout<<"Total cost: $"<

return 0;
}


Output:


Related Solutions

X Company is considering the purchase of a new processor that costs $200,000. Shipping and setup...
X Company is considering the purchase of a new processor that costs $200,000. Shipping and setup costs for the processor are estimated to be $15,000. X’s working capital requirement is expected to increase by $17,000 when the new processor begins operation and is expected to be fully recoverable at the end of the project. The processor’s useful life is expected to be 5 years and its salvage value at that point is estimated to be $25,000. Estimated revenues and expenses...
Determine whether each statement is true or false. A. Freight costs incurred in shipping products to...
Determine whether each statement is true or false. A. Freight costs incurred in shipping products to customers is properly referred to as a product rather than period cost of the selling company. B. Period costs include all selling and administrative costs, both variable and fixed. C. The salary of a manufacturing quality control inspector would typically be accounted for as manufacturing overhead. D. A retail merchandising company's cost of goods sold typically includes part of store utility costs. E. A...
vveVade, an online retailer, fulfills its online orders by shipping its products directly to customers in...
vveVade, an online retailer, fulfills its online orders by shipping its products directly to customers in all 50 states. eVade does not have a brick-and-mortar store presence in any state, but does operate distribution centers in various states across the country, including State X. Consistent with its practice in all 50 states, eVade does not collect or remit sales tax to State X. In recent court rulings, State X has taken the position that operating a distribution center within a...
I have to write a c program for shipping calculator. anything that ships over 1000 miles,...
I have to write a c program for shipping calculator. anything that ships over 1000 miles, there is an extra 10.00 charge. I have tried everything. no matter what I put, it will not add the 10.00. please help here is my code #include <stdio.h> #include <stdlib.h> int main() { double weight, miles, rate, total; printf("Enter the weight of the package:"); scanf("%lf", &weight); if (weight > 50.0) { puts("we only ship packages of 50 pounds or less."); return 0; }...
Write a program that will ask the user to enter the amount of a purchase. The...
Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 5 percent and the county sales tax is 2.5 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase plus the...
This week you will write a program that mimics an online shopping cart . You will...
This week you will write a program that mimics an online shopping cart . You will use all the programming techniques we have learned thus far this semester, including if statements, loops, lists and functions. It should include all of the following: The basics - Add items to a cart until the user says "done" and then print out a list of items in the cart and a total price. - Ensure the user types in numbers for quantities -...
Python This week you will write a program in Python that mimics an online shopping cart...
Python This week you will write a program in Python that mimics an online shopping cart . You will use all the programming techniques we have learned thus far this semester, including if statements, loops, lists and functions. It should include all of the following: The basics - Add items to a cart until the user says "done" and then print out a list of items in the cart and a total price. - Ensure the user types in numbers...
Python This week you will write a program in Pyhton that mimics an online shopping cart...
Python This week you will write a program in Pyhton that mimics an online shopping cart . You will use all the programming techniques we have learned thus far this semester, including if statements, loops, lists and functions. It should include all of the following: The basics - Add items to a cart until the user says "done" and then print out a list of items in the cart and a total price. - Ensure the user types in numbers...
Write a program that will calculate and display the cost of a gasoline purchase based on...
Write a program that will calculate and display the cost of a gasoline purchase based on the brand of gasoline, the octane rating and the amount purchased. Your program should first display a menu prompting the user for the brand of gasoline.  Next prompt the user for the amount of gasoline in liters. Finally, your program should calculate and display the cost of the gasoline purchase using the formula below. Cost of Discount Gasoline = ($2.49 - (100 - Octane Rating)...
Research Case 1 eVade, an online retailer, fulfills its online orders by shipping its products directly...
Research Case 1 eVade, an online retailer, fulfills its online orders by shipping its products directly to customers in all 50 states. eVade does not have a brick-and-mortar store presence in any state, but does operate distribution centers in various states across the country, including State X. Consistent with its practice in all 50 states, eVade does not collect or remit sales tax to State X. In recent court rulings, State X has taken the position that operating a distribution...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT