Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<iomanip>
- using namespace std;
- int main()
- {
- int resLength; //Reservation length declared
- char carType; //cartype (e or l)
- int age; // self explanatory
- double cost; //the final cost - age * car type, later will put if statement for if (resLength > 7)
- cout << "Please enter length of reservation: ";
- cin >> resLength;
- cout << "Please enter car type: ";
- cin >> carType;
- cout << "How old is the driver? ";
- cin >> age;
- //made four if statements under to calculate cost based on all possible situations
- if (carType == 'e' || 'E' && age <= 25)
- cost = resLength * 29.95;
- else if (carType == 'e' || 'E' && age > 25)
- cost = resLength * 25.95;
- else if (carType == 'l' || 'L' && age <= 25)
- cost = resLength * 49.95;
- else if (carType == 'l' || 'L' && age > 25)
- cost = resLength * 42.95;
- if (resLength > 7)
- cost = cost - (.1 * cost);
- if (carType == 'e' || carType == 'E')
- cout << "The cost for an economy car for " << resLength << " days is $" << fixed << setprecision(2) << cost << endl;
- else if (carType == 'l' || carType == 'L')
- cout << "The cost for a Luxury car for " << resLength << " days is $" << fixed << setprecision(2) << cost << endl;
- return 0;
- }
- // problem with logic error - needed to fix if statements so that other outputs could work properly
Advertisement
Add Comment
Please, Sign In to add comment