Guest User

c++prob

a guest
Feb 16th, 2016
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include<iostream>
  2. #include<iomanip>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8. int resLength; //Reservation length declared
  9. char carType; //cartype (e or l)
  10. int age; // self explanatory
  11. double cost; //the final cost - age * car type, later will put if statement for if (resLength > 7)
  12.  
  13.  
  14. cout << "Please enter length of reservation: ";
  15. cin >> resLength;
  16. cout << "Please enter car type: ";
  17. cin >> carType;
  18. cout << "How old is the driver? ";
  19. cin >> age;
  20.  
  21. //made four if statements under to calculate cost based on all possible situations
  22. if (carType == 'e' || 'E' && age <= 25)
  23. cost = resLength * 29.95;
  24. else if (carType == 'e' || 'E' && age > 25)
  25. cost = resLength * 25.95;
  26. else if (carType == 'l' || 'L' && age <= 25)
  27. cost = resLength * 49.95;
  28. else if (carType == 'l' || 'L' && age > 25)
  29. cost = resLength * 42.95;
  30.  
  31. if (resLength > 7)
  32. cost = cost - (.1 * cost);
  33.  
  34.  
  35. if (carType == 'e' || carType == 'E')
  36. cout << "The cost for an economy car for " << resLength << " days is $" << fixed << setprecision(2) << cost << endl;
  37. else if (carType == 'l' || carType == 'L')
  38. cout << "The cost for a Luxury car for " << resLength << " days is $" << fixed << setprecision(2) << cost << endl;
  39.  
  40.  
  41. return 0;
  42. }
  43.  
  44. // 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