I have to create a program, that takes a file with employee first name, last name, original salary, opens it, reads it, then does math for a raise and outputs the new data with an updated salary.
Each record has the same variables as you described. Those variables can be put into a data structure, a collection of variables:
1 2 3 4 5 6
struct Record
{
std:;string first;
std::string last;
// Other vars
};
You can then write some code, code that overloads the basic c++ in and out operations ( cin, ifstream etc ) to be able to retrieve and post data, as if it were an int, string etc.
You could then use std::vector to hold a dynamic amount of records ( You can add and take records from the file without having to change the original code, I believe someone on this forum mentions data driven code which opened my eyes up to this.
It may seem confusing as a beginner, I hope my link can help.
Its displaying that way becuase thats how you built a program. Instead of doing it all like that, use a loop. Use a for loop that loops 3 times, since you have 3 persons. Read in all the information, do the math, put it in the file. Do that 3 times.
And you do - inFile >> currentSalary1 >> currentSalary2
The program wont seek for the "50" and "60" and put them in those variables. Things will be put in the order they are in the file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
float currentSalary;
double updatedSalary;
double percentIncrease;
string firstName;
string lastName;
for(int i = 0; i < 3; i ++)
{
// read in first and last name
// read in salary and percent increase
// do calculations
// put them in the file
}
You can read in all info about one person, do the calculations and then put it in the file. Then next loop round it will do the same for next person, and then for the last one.