> C++ programming. NEED HELP?

C++ programming. NEED HELP?

Posted at: 2014-12-18 
if (salary <= 'z' && salary >= 'a' || years_of_service <= 'z' && years_of_service >= 'a')

Why are you comparing numeric data with alphabetic characters?

} else if (get_bonus == true)

You probably want

}

if (get_bonus == true)

so

(get_bonus == false);

should be

else

---------------

Edit: if you want the program to react to alphabetic characters (without crashing) then you have to read it in as a string and then analyze the content of the string. There are various ways of doing that depending on how forgiving you want to be.

For instance, you can simply look at the first character to see if it's numeric, but it would still crash if someone typed 123w. I'm surprised there aren't built-in functions to make console input more foolproof, although, nowadays, GUI forms are used and those do have ways of ignoring alpha chars you attempt to type into a numeric field.

because i want the program to say invalid information if for years of service they input letters. What do you mean by if (get_bonus == true)

so

(get_bonus == false);

should be

else

***** I need help with this program im trying to create in C++.the program runs but it doesn't run properly. the problem is that it executes commands that should not be executed unless bool is true. can you guys please help. ***



#include

#include

using namespace std;

int main()

{

double bonus, salary ;

int years_of_service, current_year;

char manager;

bool get_bonus = false;

bool get_leapyear = false;

cout << "Enter years of service:";

cin >> years_of_service;



cout << endl << "enter current year:";

cin >> current_year;

cout << endl << "Enter salary:";

cin >> salary;

cout << endl << "Are you a manager(Y for yes, N for no):";

cin >> manager;

manager = tolower(manager);

if (salary <= 'z' && salary >= 'a' || years_of_service <= 'z' && years_of_service >= 'a')

cout << endl << "INVALID ENTRY!! please try again...";

else if (manager == 'n' && salary < 100000 && years_of_service >= 5)

{

get_bonus = true;

cout << endl << "10% BONUS APPLIES";

salary = salary * .1;

bonus = salary;

}

else if (current_year % 400 == 0 || current_year % 4 == 0 && current_year % 100 != 0)

{

get_leapyear = true;

cout << endl << endl << "ADDITIONAL BONUS APPLIES DUE TO LEAP YEAR";

bonus = salary * 2;

}



else if

(get_bonus == true)

cout << endl << endl << "Total Bonus Amount:" << bonus;

(get_bonus == false);

cout << endl << "NO BONUS :-(";

cout << endl << "\npress any key to continue.";

_getch();

return 0;

}