the first loop is employee number 1. after i have input the relevant data, the next employee number is 7? can someone tell me why the for loop skip 2-6?
THANK YOU SO MUCH
do
{
cout<<"Please enter the number of employee you wish to create = ";
cin>>NumberOfEmployee;
cin.ignore(5,'\n');
if (NumberOfEmployee > 20)
{
cout<<"Maximum 20 Employees for each department.\n"
<<endl;
}
}while(NumberOfEmployee>20);
for(i = 1; i<=NumberOfEmployee;i++)
{
cout<<"Employee Number "<<i
<<endl;
do
{
again = false;
cout<<"Please enter the Employee's ID = ";
cin.getline(temp,80 ,'\n');
if(strlen(temp)!=6)
{
cout<<"The length of Employee ID must be 6 characters.\n"
<<endl;
again = true;
}
if(temp[0]<'A' || temp[0]>'Z')
{
cout<<"The first character of the Employee ID must be a uppercase letter.\n"
<<endl;
again = true;
}
for(i=1; i<=5;i++)
{
if(!isdigit(temp[i]))
{
//system("cls");
cout<<"The last 5 characters of the Employee ID must all be in digits.\n"
<<endl;
again = true;
break;
}
}
}while(again);
strcpy(EmployeeID,temp);
do
{
again = false;
cout<<"Please enter the name of the Employee = ";
cin.getline(temp,80,'\n');
if(strlen(temp)>20)
{
//system("cls");
cout<<"Employee's name must be at most 20 characters.\n"
<<endl;
again = true;
}
}while(again);
strcpy(Name,temp);
do
{
again = false;
cout<<"Please enter the Employee's telephone number = ";
cin.getline(temp,80,'\n');
if(strlen(temp)!=7)
{
//system("cls");
cout<<"Telephone number must be at 7 digits.\n"
<<endl;
again = true;
}
}while(again);
strcpy(TelephoneNumber,temp);
do
{
again = false;
cout<<"Is the employee salaried employee(S) or an hourly paid employee(H) = ";
cin>>EmployeeType;
cin.ignore(5,'\n');
if(EmployeeType !='H'&& EmployeeType !='S')
{
cout<<"Please enter either [S] for salaried employee or [H] for hourly paid employee.\n"
<<endl;
again = true;
}
}while(again==true);
cout<<setiosflags(ios::left)<<setw(7)<<EmployeeID
<<setw(21)<<Name
<<resetiosflags(ios::left)<<setw(8)<<TelephoneNumber
<<setw(2)<<EmployeeType
<<endl;
outfile<<setiosflags(ios::left)<<setw(7)<<EmployeeID
<<setw(21)<<Name
<<resetiosflags(ios::left)<<setw(8)<<TelephoneNumber
<<setw(2)<<EmployeeType
<<endl;
cout<<endl;
system("pause");
system("cls");
}
I believe it'd be because you are using the same variable for two loops.
Starts at 1 at first loop. When it gets to second loop it goes to 1 again and increments to 6 then it returns to first loop and adds one more to become 7.