//Program checks employment status, if part time, NO VACATION, if full time, program goes into if/else nest and asks for number of years working at company. More than five years,full time employee granted 3weeks of vacation. Five years or less, full time employee is granted 2weeks of vacation.
#include <iostream>
using namespace std;
char empTime=' ';
int years=0;
int main()
{
cout<<"Employment status? (F=fulltime, P=parttime)";
cin>>empTime;
cin.ignore(100,'\n'); [B]//(1)[/B]
empTime=toupper(empTime);
if(empTime=='F')
{
cout<<"Years working at company XYZ?";
cin>>years;
if(years>5)
{
cout<<"Vacation weeks = 3";
}
else if(years<=5 && years>=0){ [B]//(2)[/B]
cout<<"Vacation weeks = 2";
}
else{cout<<"Invalid input";}
}
else if(empTime=='P'){
cout<<"Vacation weeks = 0";
}
else{cout<<"Invalid input";}
cin.get();
}
(1) I put ignore function in b/c I thought clearing the buffer may help..but I don't think char data type needs clearing..does it?
MAIN PROBLEM:
(2)This is where I suspect the problem is...when I run the program, I input 'F', and then when the screen displays number of years I punch in a bunch of random charcters ex "dhsdkhfebs" [enter] --> and right away it displays "vacation weeks = 2", but I was hoping it would go to "invalid input".
When I put a negative number in..it goes to "Invalid input"...but not charcters..
Any help would be appreciated. Please note that I am only a week in learning c++ and am using a book from 2003, so if my syntax is either too formal, off, retarded in anyway please correct me. Also if I am using unneeded functions or anything else that's bloated please tell me, better I fix bad habits now than later.
P.S.
_btw I use cin.get(); so user has to press [enter] before the program returns 0.
_using codeblocks as my compiler.