-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShippingCost_Calculator.cpp
More file actions
57 lines (50 loc) · 1.57 KB
/
ShippingCost_Calculator.cpp
File metadata and controls
57 lines (50 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*PROJECT
E-Commerce Website — Shipping Cost Calculator
An online store wants a function to compute shipping cost.
Write a function that takes:
Weight (kg)
Distance (km)
Delivery type: standard or express
Rules:
1. Base cost = 100
2. Cost per kg = 50
3. Cost per km = 1
4. Express adds +500 extra
5. Return total shipping cost.
Also create a function to display a shipping receipt.*/
#include<iostream>
using namespace std;
int shippingCost(int weight, int distance, string shippingType)
{
int base_cost = 100;
int Costperkg = 50;
int Costperkm = 1;
int total_shipping_cost = base_cost + (weight * Costperkg) + (distance * Costperkm);
if(shippingType == "express"){
total_shipping_cost = total_shipping_cost + 500;
}
return total_shipping_cost;
}
int shipping_receipt(int weight, int distance, string shippingType, int total_shipping_cost){
cout<<" SHIPPING RECEIPT "<<endl;
cout<<" item weight: "<<weight<<endl;
cout<<" item distance: "<<distance<<endl;
cout<<" shipping type: "<<shippingType<<endl;
cout<<" total shipping cost: "<<total_shipping_cost<<endl;
cout<<" thank you ";
return 0;
}
int main()
{
int weight, distance;
string shippingType;
cout<<"Enter item weight: ";
cin>>weight;
cout<<"Enter item distance: ";
cin>>distance;
cout<<"Enter shipping type: ";
cin>>shippingType;
int total_shipping_cost = shippingCost(weight, distance, shippingType);
shipping_receipt(weight, distance, shippingType, total_shipping_cost);
return 0;
}