Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-----------------------------------------------------------------------
- // By: Matt White, 10-12-08, ITCS1212-001, ShipCost2.cpp
- // Purpose: Same as #1, with added region cost
- //-----------------------------------------------------------------------
- #include <iostream>
- using namespace std;
- double GetShipCost(double dWeight);
- double GetRegionCost(char cRegion);
- int main(){
- double dWeight; char cRegion;
- cout << "Item Weight = "; cin >> dWeight;
- cout << "Item Region = "; cin >> cRegion;
- cout << "\n\tWeight: " << dWeight << "\n\tRegion: " << (char)toupper(cRegion) << "\n\tPrice: " << GetShipCost(dWeight) + GetRegionCost(cRegion);
- return 0;
- }
- double GetShipCost(double dWeight){
- double dCost = 0; // Initial Cost
- double dAdd = 0; // Additonal amount added to initail cost
- int dLimit = 0; // The limit of when add extra $$ for each pound over (used in final cost calculation)
- if (dWeight<5) {dCost=3; dLimit=0; dAdd = 0;}
- if (dWeight>=5 && dWeight<10) {dCost=3; dLimit=5; if (dWeight>5) dAdd = .25;}
- if (dWeight>=10 && dWeight<15) {dCost=5.50; dLimit=10; if (dWeight>10) dAdd = .20;}
- if (dWeight>=15) {dCost=8.50; dLimit=15; if (dWeight>15) dAdd = .10;}
- return dCost + (dAdd*(dWeight-dLimit));
- }
- double GetRegionCost(char cRegion){
- double dRet;
- switch (toupper(cRegion)){
- case 'A': dRet = 1.0; break;
- case 'B': dRet = 1.5; break;
- case 'C': dRet = 2.0; break;
- case 'D': dRet = 2.5; break;
- }
- return dRet;
- }
- // ----------------
- // Directions:
- // 1. Same as #1, with added Region cost.
- // 2. The funtion must use switch case. (The values are self-explanatory)
- // ----------------
Add Comment
Please, Sign In to add comment