I'm having a problem with my while loop, it won't stop prompting for input. I'm using a while loop and want to bail out when the user just presses 'enter' (\0). Perhaps somebody could give me a hint as to what I'm doing wrong?
Code:
#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;
struct Employee
{
char firstName[35];
char lastName[35];
char hireDate[11];
char SSN[12];
int Hours;
float payRate;
};
float PayCalc(int, float);
int main(void)
{
const int max_count(50);
Employee Emps[max_count];
int count(0);
while(Emps[count].firstName != '\0')
{
cout << "Employee's first name: ";
cin >> Emps[count].firstName;
cout << Emps[count].firstName << "'s last name is: ";
cin >> Emps[count].lastName;
cout << Emps[count].firstName << "'s hire date is: ";
cin >> Emps[count].hireDate;
cout << Emps[count].firstName << "'s social security number: ";
cin >> Emps[count].SSN;
cout << "Number of hours that " << Emps[count].firstName << " worked: ";
cin >> Emps[count].Hours;
cout << Emps[count].firstName << "'s pay rate: ";
cin >> Emps[count].payRate;
count++;
cin.ignore(100, '\n');
}
for(int a(0); a < count; a++)
{
cout << Emps[a].lastName << ", " << Emps[a].firstName << setw(20) << Emps[a].hireDate << setw(5);
cout << Emps[a].SSN << setw(5) << Emps[a].Hours << setw(5) << PayCalc(Emps[a].Hours, Emps[a].payRate) << endl;
}
cout << right << count << endl;
return 0;
}
float PayCalc(int a, float b)
{
return float(a) * b;
}
I hope that this looks right on the screen, it's my first time to post and I am trying to abide by the forum bylaws. Anyhow, I'm not looking for the actual code, I'd like to figure this out...However, if somebody could help me in seeing what I'm doing wrong then I would greatly appreciate it.