Hi everyone, I was wondering if anyone could help me figure out this issue I am having with a program I have written. The problem is after you type in the number of days you want to rent the car for if it is less than 0 or greater than 30 it is supposed to loop back to What class of car do you want and give an message such as invalid entry. I have tried all type of loops, while loops, do while loops if, if , and I still cannot figure it out the program is written below. Thanks in advance for your help it has been kicking my butt. John
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main (){
cout.setf(std::ios_base::fixed); // Using precision function to limit decimal output to 2
cout.setf(std::ios_base::showpoint);
cout.precision(2);
char carType = 0; // character type will be car type selected
int days = (0 <= 30);
cout << "Welcome to the Car Rental Program.\n";
do {
cout << "What class of car do you want (A, B, C, or D)? "; // Asking user what type of car they would like to choose.
cin >> carType; // User enters car type
switch (carType){
case 'a':
case 'A':
cout << "How many days will you keep the car (no more than 30 days)? "; // Asking user number of days car is needed
cin >> days;
cout << "Your price will be $" << 30*days*1.06 << ". Is this OK (Y or N)?";
cin >> carType;
break;
case 'b':
case 'B':
cout << "How many days will you keep the car (no more than 30 days)? ";
cin >> days;
cout << "Your price will be $" << 40*days*1.06 << ". Is this OK (Y or N)?";
cin >> carType;
break;
case 'c':
case 'C':
cout << "How many days will you keep the car (no more than 30 days)? ";
cin >> days;
cout << "Your price will be $" << 55*days*1.06 << ". Is this OK (Y or N)?";
cin >> carType;
break;
case 'd':
case 'D':
cout << "How many days will you keep the car (no more than 30 days)? ";
cin >> days;
cout << "Your price will be $" << 80*days*1.06 << ". Is this OK (Y or N)?";
cin >> carType;
break;
default :
cout << "Invalid Entry please try again." << carType<< "\n"; // If user selects character other than a, b, c, d, in lower case or caps will get error message
}
} while (carType !='Y' && carType != 'y'); // if user chooses Y they will get a thank you message can either be caps or lower case.
cout << "Thank You!";
return 0;
}
Thanks again for all the help,
John