0

Not Accepting Last Input

#include <iostream> #include <cmath> #include <string> //#include <ctype> using namespace std; //char marital //char tolower(marital); // Takes driving exp and returns the additional fee int driversgroup(int drivingXp) { if (drivingXp>0 && drivingXp<2) { return 150;} else if (drivingXp>3 && drivingXp<5) { return 80;} else if(drivingXp>6){ return 30;} } // Takes the driving age and returns the additional fee must not be <18 int ageGroup(int driverage) { if (driverage>18 && driverage<28){ return 50;} else if (driverage>29 && driverage<45){ return 30;} else if (driverage>46 && driverage<60){ return 20;} else if (driverage>=61){ return 30;} } //Takes the gender of driver and test for male and return additnal fee bool isMale(char gender) { if (gender =='M' || gender== 'm') { return 10; } else { return 0; } } //Takes the marital status of driver and returns addtional fee int isAvailable(int marital) { if (marital =='S' || 's'|| 'D'|| 'd'){ return 40; } } // Computes Total premium paid int computePremium(int driverage, int drivingXp, int gender, int marital) { int Totalpremium= driversgroup(drivingXp) + ageGroup(driverage) + isMale(gender) + isAvailable(marital); cout << "Your Total premium is R" << Totalpremium << endl; } int main() { int driverage; int drivingXp; char gender; char marital; cout << "What is your age?"; cin >> driverage; cout << "How long have you been driving? (in years)"; cin >> drivingXp; cout << "Are you male or female? (M or F)"; cin >> gender; cout << "Are you married?(S for single, D for divorce, M for married or L for living with partner)"; cin >> marital; /* getline(cin,input) for (int input=0;input.length();marital++) input[marital]=tolower(input[marital]); */ //std::char (tolower('marital'))<<endl; if(marital != 'm'|| 'd'|| 's'|| 'l'){ cout << "Try again, invalid entry";

19th Sep 2017, 11:42 AM
gorgamin
gorgamin - avatar
1 Odpowiedź
+ 6
Your problem is your if test: if(marital != 'm'|| 'd'|| 's'|| 'l') It will always be true as 'd' is non-zero. It should be written as: if(marital != 'm' && marital != 'd' && marital != 's' && marital != 'l')
19th Sep 2017, 2:00 PM
John Wells
John Wells - avatar