M
msammart
Hey, i have a payroll system and i'm tyring to have it so the user can
select an option from the menu and then be able to change one of the
employee's salaries based on the user ID input. ( data is read in from
a text file.)
If (choice == 2)
{
cout << "Please Enter the Employee's ID Number (ex. Test0001 <case
sensitive>): " << endl;
cin >> EmpID;
cout << " " << endl;
char buffer[20];
{
cout << "Please Enter a New Salary for the Employee. " << endl;
cout << "$";
cin >> Newpay;
cout << " " << endl;
char buffer[20];
char backupmatrix[100][100]; //to take full file into "backupmatrix"
ifstream employeefile ("employee.txt"); //read from file
if (! employeefile.is_open())
{ cout << "Error opening file"; exit (1); }
int linecount = 0; //separates lines in file when taken out
int IDlength = strlen(EmpID); //gets length of ID
while (! employeefile.eof() )
{
employeefile.getline (backupmatrix[linecount],100); //gets single line
cout << backupmatrix[linecount] << endl; //output for testing purposes
for( int counter = 0; counter < IDlength; counter++) //checks
employee's ID to inputted ID
{
if( backupmatrix[linecount][counter+2] != EmpID[counter]
) {break;} //if don't match, leave for loop
if( counter == (IDlength-1) )//if full ID matches, change salary
{cout << "HEY" << endl;} //for debugging purposes, replace cout with
means of
/changing SALARY portion of the line "backupmatrix[linecount]"
}
linecount++;
}
}
}
}
}
So far when its ran and a correct employee ID is input {cout << "HEY"
<< endl;} does output like intended. This is just a section of the
code. Any suggestions or changes are greatly appreciated. Thanks!
select an option from the menu and then be able to change one of the
employee's salaries based on the user ID input. ( data is read in from
a text file.)
If (choice == 2)
{
cout << "Please Enter the Employee's ID Number (ex. Test0001 <case
sensitive>): " << endl;
cin >> EmpID;
cout << " " << endl;
char buffer[20];
{
cout << "Please Enter a New Salary for the Employee. " << endl;
cout << "$";
cin >> Newpay;
cout << " " << endl;
char buffer[20];
char backupmatrix[100][100]; //to take full file into "backupmatrix"
ifstream employeefile ("employee.txt"); //read from file
if (! employeefile.is_open())
{ cout << "Error opening file"; exit (1); }
int linecount = 0; //separates lines in file when taken out
int IDlength = strlen(EmpID); //gets length of ID
while (! employeefile.eof() )
{
employeefile.getline (backupmatrix[linecount],100); //gets single line
cout << backupmatrix[linecount] << endl; //output for testing purposes
for( int counter = 0; counter < IDlength; counter++) //checks
employee's ID to inputted ID
{
if( backupmatrix[linecount][counter+2] != EmpID[counter]
) {break;} //if don't match, leave for loop
if( counter == (IDlength-1) )//if full ID matches, change salary
{cout << "HEY" << endl;} //for debugging purposes, replace cout with
means of
/changing SALARY portion of the line "backupmatrix[linecount]"
}
linecount++;
}
}
}
}
}
So far when its ran and a correct employee ID is input {cout << "HEY"
<< endl;} does output like intended. This is just a section of the
code. Any suggestions or changes are greatly appreciated. Thanks!