In: Computer Science
CODE IN C++ PLEASE
Write a program to implement the algorithm that you designed in Exercise 19 of Chapter 1. Your program should allow the user to buy as many items as the user desires. Instructions for Exercise 19 of Chapter 1 have been posted below for your convenience. Exercise 19 Jason typically uses the Internet to buy various items. If the total cost of the items ordered, at one time, is $200 or more, then the shipping and handling is free; otherwise, the shipping and handling is $10 per item. Design an algorithm that prompts Jason to enter the number of items ordered and the price of each item. The algorithm then outputs the total shipping and handling fee, and the billing amount. Your algorithm must use a loop (repetition structure) to get the price of each item. (For simplicity, you may assume that Jason orders no more than five items at a time.) An example of the program is shown below: Enter the number of items ordered: 3 Enter the price of item no. 1: 79.00 Enter the price of item no. 2: 23.50 Enter the price of item no. 3: 1.99 The shipping and handling fee is: $30.00 The billing amount is: $134.49 Since your program handles currency, make sure to use a data type that can store decimals with a decimal precision of 2.
#include <iostream>
using namespace std;
int main()
{
float n, temp, totalPrize = 0;
cout<<"Enter the number of items ordered:
";
cin>>n;
for (int i = 1; i <= n; ++i)
{
cout<<"Enter the price of
item no. "<<i<<": ";
cin>>temp;
totalPrize = totalPrize +
temp;
}
if (totalPrize >= 200)
{
cout<<"The shipping and
handling fee is: $0.00"<<endl;
cout<<"The billing amount is:
$"<<totalPrize<<endl;
} else {
float shippingAndHandlingFee = n *
10;
totalPrize = totalPrize +
shippingAndHandlingFee;
cout<<"The shipping and
handling fee is:
$"<<shippingAndHandlingFee<<endl;
cout<<"The billing amount is:
$"<<totalPrize+n<<endl;
}
return 0;
}