Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <cmath>
- #include <sstream>
- using namespace std;
- int main() {
- const double tax = 4;
- const double vat = 0.25;
- const double disc1 = 0.35;
- const double disc2 = 0.85;
- const double hStart = 8;
- const double hEnd = 18.5;
- double priceTotal, mTotal, mFullTax=0, mNoTax;
- double h1, m1, h2, m2, h1m1, h2m2;
- //Input
- string input1, input2;
- getline(cin, input1);
- int pos1 = input1.find(":");
- input1.replace(pos1, 1, " ");
- istringstream iss(input1);
- iss >> h1 >> m1;
- iss.clear();
- getline(cin, input2);
- int pos2 = input2.find(":");
- input2.replace(pos2, 1, " ");
- iss.str(input2);
- iss >> h2 >> m2;
- iss.clear();
- //Calculate
- h1m1 = (h1 + (m1 / 60));
- h1m1 = (ceil(h1m1 * 100) / 100);
- h2m2 = (h2 + (m2 / 60));
- h2m2 = (ceil(h2m2 * 100) / 100);
- for(double i = h1m1; i <= h2m2; i += 0.01) {
- if(i > hStart && i < hEnd) {
- mFullTax++;
- }
- }
- mFullTax = ((mFullTax * 60) / 100);
- mTotal = (((h2 - h1) * 60) + (m2 - m1));
- mNoTax = (mTotal - mFullTax);
- priceTotal = ((mFullTax * tax) + ((mNoTax * tax) * disc1));
- if(mTotal > 30) {
- priceTotal *= disc2;
- }
- priceTotal = (priceTotal + (priceTotal * vat));
- //Output
- cout << "Start: " << h1 << ":" << m1 << endl;
- cout << "End: " << h2 << ":" << m2 << endl;
- cout << fixed << setprecision(2) << "Cost: " << priceTotal << " kr" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement