Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. float home (float g) // home function
  5. {
  6.     float cost;
  7.     cost = 5+(0.0005 * g);
  8.     return (cost);
  9. }
  10. float com (float g) // commercial function
  11. {
  12.     float cost;
  13.     if (g < 4000000)
  14.     {
  15.         cost = 1000;
  16.     }
  17.     else
  18.     {
  19.         cost = 1000 + (0.00025 * (g - 4000000));
  20.     }
  21.     return (cost);
  22. }
  23. float ind (float g) //industrial function
  24. {
  25.     float cost;
  26.     if (g < 4000000)
  27.     {
  28.         cost = 1000;
  29.     }
  30.     else if (g > 4000000 && g < 10000000)
  31.     {
  32.         cost = 2000;
  33.     }
  34.     else
  35.     {
  36.         cost = 3000;
  37.     }
  38.     return (cost);
  39. }
  40.  
  41. int main()
  42. {
  43.     int account;
  44.     char type = 0;
  45.     float g, cost;
  46.     cout << "Please input your account number: \n";
  47.     cin >> account;
  48.     cout << "Please enter your usage in gallons.\n";
  49.     cin >> g;
  50.     cout << "Now please enter your account type.\nType h for home, c for commercial, or i for industrial.\nThanks!\n";
  51.     do {
  52.         cin >> type;
  53.         if (type == 'h'){ break; }
  54.         if (type == 'c'){ break; }
  55.         if (type == 'i'){ break; }
  56.  
  57.     } while (type == 0);
  58.  
  59.  
  60.     if (type == 'h')
  61.     {
  62.         cost = home (g);
  63.     }
  64.     else if(type == 'c')
  65.     {
  66.         cost = com (g);
  67.     }
  68.     else
  69.     {
  70.         cost = ind (g);
  71.     }
  72.    
  73.     cout << "Hi " << account << ", your fee is: $" << cost << endl;
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement