Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  HW5
Language: C/C++
Code:
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;
      
     int main()
     {
             double minutes;
             char package;
            const double PACK_A= 39.99;
             const double MIN_A= 0.45;
             const double PACK_B = 59.99;
             const double MIN_B = 0.40;
             const double PACK_C = 69.99;
             double total;
     
             cout << "Please enter which package you have (A,B, or C): "<<endl;
             cin >> package;
      
             switch (package)
             {
                     case 'A':
                     case 'a': 
                             cout << "Please entaer how many minutes were used: "<<endl;
                             cin >> minutes;
      
                             if (minutes < 0)
                             {
                                     cout << "Invalid.";
                                     return 0;
                             }
                             if (minutes > 450)
                             {
                                    total = PACK_A + (minutes-450)*MIN_A;
                                     cout << "Your bill total is $" << setprecision(2) << fixed << total << endl;
                                     return 0;
      
                             }
                             if (minutes <= 450)
                             {
                                     total= PACK_A;
                                     cout << "Your bill total is $" << setprecision(2) << fixed << total << endl;
                                     return 0;
                             }
                     case 'B':
                     case 'b':
                             cout << "Please enter number of minutes used: "<<endl;
                             cin >> minutes;
      
                             if (minutes < 0)
                             {
                                     cout << "Invalid"<<endl;
                                     return 0;
                             }
                             if (minutes > 900)
                             {
                                     total= PACK_B + (minutes-900)*MIN_B;
                                     cout << "Your bill total is $" << setprecision(2) << fixed << total << endl;
                                     return 0;
      
                             }
                             if (minutes <= 900)
                             {
                                     total = PACK_B;
                                     cout << "The total cost is $" << setprecision(2) << fixed << total << endl;
                                     return 0;
                             }
                     case 'C':
                     case 'c':
                             total = PACK_C;
                             cout << "Your bill total is $" << setprecision(2) << fixed << total<< endl;
                     default: cout << "Invalid input. Please enter in A,B, or C";
             }
             return 0;
}
Comments: