Advertisement
fabbe680

Phone Tax v1.0

Dec 6th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <cmath>
  5. #include <sstream>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.  
  11. const double tax = 4;
  12. const double vat = 0.25;
  13. const double disc1 = 0.35;
  14. const double disc2 = 0.85;
  15. const double hStart = 8;
  16. const double hEnd = 18.5;
  17. double priceTotal, mTotal, mFullTax=0, mNoTax;
  18. double h1, m1, h2, m2, h1m1, h2m2;
  19.  
  20. //Input
  21.  
  22. string input1, input2;
  23.  
  24. getline(cin, input1);
  25.  
  26. int pos1 = input1.find(":");
  27. input1.replace(pos1, 1, " ");
  28.  
  29. istringstream iss(input1);
  30. iss >> h1 >> m1;
  31. iss.clear();
  32.  
  33. getline(cin, input2);
  34.  
  35. int pos2 = input2.find(":");
  36. input2.replace(pos2, 1, " ");
  37.  
  38. iss.str(input2);
  39. iss >> h2 >> m2;
  40. iss.clear();
  41.  
  42. //Calculate
  43.  
  44. h1m1 = (h1 + (m1 / 60));
  45. h1m1 = (ceil(h1m1 * 100) / 100);
  46. h2m2 = (h2 + (m2 / 60));
  47. h2m2 = (ceil(h2m2 * 100) / 100);
  48.  
  49. for(double i = h1m1; i <= h2m2; i += 0.01) {
  50. if(i > hStart && i < hEnd) {
  51. mFullTax++;
  52. }
  53. }
  54.  
  55. mFullTax = ((mFullTax * 60) / 100);
  56. mTotal = (((h2 - h1) * 60) + (m2 - m1));
  57. mNoTax = (mTotal - mFullTax);
  58.  
  59. priceTotal = ((mFullTax * tax) + ((mNoTax * tax) * disc1));
  60.  
  61. if(mTotal > 30) {
  62. priceTotal *= disc2;
  63. }
  64.  
  65. priceTotal = (priceTotal + (priceTotal * vat));
  66.  
  67. //Output
  68.  
  69. cout << "Start: " << h1 << ":" << m1 << endl;
  70. cout << "End: " << h2 << ":" << m2 << endl;
  71. cout << fixed << setprecision(2) << "Cost: " << priceTotal << " kr" << endl;
  72.  
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement