Advertisement
tuldok89

Parking Fee

Nov 16th, 2011
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <QtCore/QCoreApplication>
  2. #include <QTextStream>
  3. #include <cstdlib>
  4.  
  5. QTextStream cin(stdin, QIODevice::ReadOnly);
  6. QTextStream cout(stdout, QIODevice::WriteOnly);
  7.  
  8. double computeBill(int hours)
  9. {
  10.     if (hours <= 3)
  11.         return 2.0;
  12.     else
  13.     {
  14.         int hourDifference = hours-3;
  15.         double totalBill;
  16.  
  17.         totalBill = (hourDifference * 0.5) + 2;
  18.         if (totalBill <= 10)
  19.             return totalBill;
  20.         else
  21.             return 10.0;
  22.     }
  23. }
  24.  
  25. int main(int argc, char *argv[])
  26. {
  27.     QCoreApplication a(argc, argv);
  28.     int hour1, hour2, hour3;
  29.     double fee1, fee2, fee3, totalFee;
  30.  
  31.     cout << "Parking Fee Calculator\n\n"
  32.          << "Enter the length of stay for three customers...\n"
  33.          << "Customer 1: ";
  34.     cout.flush();
  35.     cin >> hour1;
  36.  
  37.     cout << "Customer 2: ";
  38.     cout.flush();
  39.     cin >> hour2;
  40.  
  41.     cout << "Customer 3: ";
  42.     cout.flush();
  43.     cin >> hour3;
  44.  
  45.     fee1 = computeBill(hour1);
  46.     fee2 = computeBill(hour2);
  47.     fee3 = computeBill(hour3);
  48.     totalFee = fee1 + fee2 + fee3;
  49.  
  50.     cout << "\nParking Fees...\n"
  51.          << QString("Customer 1: %1\n").arg(fee1, 0, 'f', 2)
  52.          << QString("Customer 2: %1\n").arg(fee2, 0, 'f', 2)
  53.          << QString("Customer 3: %1\n\n").arg(fee3, 0, 'f', 2)
  54.          << QString("Total Parking fees: %1").arg(totalFee, 0, 'f', 2)
  55.          << endl;
  56.  
  57.     return EXIT_SUCCESS;
  58. }
  59.  
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement