PLEASE HELP

Could someone please help me with the following code. I've tried everything but I can't seem to get it to work.

The user is asked to enter the name (string), enter their id# string, then evaluate the id. the user is then asked to enter the hours, and finally the user is asked are there more employees. When I get to this point the function loops.

#include<iostream>
#include<string>
#include <algorithm>
using namespace std;

string GetEmployeeName();
bool validid(string);
bool MoreEmployees(int);
float getpayrate(string Id);



int main()
{
int n = 0;
float hrs[100],gross[100];//,bonus[100];
string EmployeeName[100],Eid[100] ;
// string Id;
bool valid = true;

do
{
EmployeeName[n]=GetEmployeeName();

do
{
cout<<"Enter the employee ID#: ";
getline(cin,Eid[n]);
valid = validid(Eid[n]);
if (!valid)
cout<<"********** INVALID EMPLOYEE ID ********** \nPlease Re-";
} while (!valid);

cout<<"Enter the hours worked: ";
cin>>hrs[n];
gross[n] = hrs[n] * getpayrate(Eid[n]);



} while(MoreEmployees(n++));




system("pause");
return 0;
}

string GetEmployeeName()
{
string Ename;
cout<<"Enter the employee name: ";
getline(cin,Ename);
return Ename;
}

bool validid(string Id)
{
bool result=true;
Id[0]=toupper(Id[0]);
if(Id.length()!=7)
result=false;
else if (Id[0]!='A'&&Id[0]!='B'&&Id[0]!='C'&&Id[0]!='D'&&Id[0]!='E'&&Id[0]!='F')
result=false;
else if (Id[5]!='-')
result=false;
else if (Id[6]!='0'&&Id[6]!='1'&&Id[6]!='2')
result=false;
return result;

}

bool MoreEmployees(int n)
{
string UserResponse;

do
{
cout << "Are there more employees? Enter Y or N here. ----> ";

getline(cin, UserResponse);

transform(UserResponse.begin(), UserResponse.end(), UserResponse.begin(), toupper);

} while ((UserResponse.compare(0, 1, "Y") != 0 && UserResponse.compare(0, 1, "N") != 0) ||
UserResponse.length() != 1);

return (UserResponse == "Y" && n < 100) ? true : false;
}



float getpayrate(string Id1)
{
float pyrt=0.0;
if(Id1[0]=='A')
pyrt=7.82f;
else if(Id1[0]=='B')
pyrt=12.56f;
else if(Id1[0]=='C')
pyrt=18.21f;
else if(Id1[0]=='D')
pyrt=25.73f;
else if(Id1[0]=='E')
pyrt=28.92f;
else if(Id1[0]=='F')
pyrt=31.26f;
return pyrt;
}
Last edited on
Topic archived. No new replies allowed.