Guest User

Untitled

a guest
May 25th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. //-----------------------------------------------------------------------
  2. // By: Matt White, 10-12-08, ITCS1212-001, ShipCost3.cpp
  3. // Purpose: Same as #2, with added error handling
  4. //-----------------------------------------------------------------------
  5. #include <iostream>
  6. using namespace std;
  7. double GetShipCost(double dWeight);
  8. double GetRegionCost(char cRegion);
  9.  
  10. int main(){
  11. double dWeight; char cRegion;
  12. cout << "Item Weight = "; cin >> dWeight;
  13. cout << "Item Region = "; cin >> cRegion;
  14.  
  15. cRegion = toupper(cRegion); // Error handling code...
  16. if (dWeight<1 || dWeight>50) {cout << "\n\tError: Weight Range = 1-50"; goto End;}
  17. if (cRegion<65 || cRegion>68) {cout << "\n\tError: Region Range = A-D"; goto End;}
  18.  
  19. cout << "\n\tWeight: " << dWeight << "\n\tRegion: " << (char)toupper(cRegion) << "\n\tPrice: " << GetShipCost(dWeight) + GetRegionCost(cRegion);
  20. End:
  21. return 0;
  22. }
  23.  
  24.  
  25. double GetShipCost(double dWeight){
  26. double dCost = 0; // Initial Cost
  27. double dAdd = 0; // Additonal amount added to initail cost
  28. int dLimit = 0; // The limit of when add extra $$ for each pound over (used in final cost calculation)
  29.  
  30. if (dWeight<5) {dCost=3; dLimit=0; dAdd = 0;}
  31. if (dWeight>=5 && dWeight<10) {dCost=3; dLimit=5; if (dWeight>5) dAdd = .25;}
  32. if (dWeight>=10 && dWeight<15) {dCost=5.50; dLimit=10; if (dWeight>10) dAdd = .20;}
  33. if (dWeight>=15) {dCost=8.50; dLimit=15; if (dWeight>15) dAdd = .10;}
  34.  
  35. return dCost + (dAdd*(dWeight-dLimit));
  36. }
  37.  
  38. double GetRegionCost(char cRegion){
  39. double dRet;
  40. switch (toupper(cRegion)){
  41. case 'A': dRet = 1.0; break;
  42. case 'B': dRet = 1.5; break;
  43. case 'C': dRet = 2.0; break;
  44. case 'D': dRet = 2.5; break;
  45. }
  46. return dRet;
  47. }
  48.  
  49. // ----------------
  50. // Directions:
  51. // 1. Weight can only be (0,50) = 1-50
  52. // 2. Region can only be A-D (ASCII: 65-68)
  53. // 3. Region accepts lower & uppercase
  54. // ----------------
Add Comment
Please, Sign In to add comment