32.7k views
1 vote
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 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.)

User Aphax
by
5.2k points

1 Answer

2 votes

Answer:

Here is Algorithm.

1.Read the number of items "n".

2.for i=1 to n

2.1 read cost of each items

2.2 calculate total cost of all items and assign to tot_cost

3. if the total cost is less than 200

3.1 add 10 per item(hipping and handling charge) to tot_cost

4. print the total cost

5.end the program

Implementation in C++.

// include headers

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variables

int no_item;

double tot_cost=0,cost;

cout<<"enter the number of items:";

// read number of items

cin>>no_item;

for(int a=1;a<=no_item;a++)

{

cout<<"enter the cost of item "<<a<<":";

// read cost of each item

cin>>cost;

// calculate total cost

tot_cost=tot_cost+cost;

}

// if total cost is less than 200

// add 10 per item

if(tot_cost<200)

tot_cost=tot_cost+no_item*10;

// print the total cost

cout<<"total cost of all item is:"<<tot_cost<<endl;

return 0;

}

Output:

enter the number of items:4

enter the cost of item 1:55

enter the cost of item 2:80

enter the cost of item 3:34

enter the cost of item 4:49

total cost of all item is:218

User Jeremy Grozavescu
by
6.1k points