Ok.
First thing,
Instead of doing
while (!infile.eof())
Do this
1 2
|
string Current_String;
While(infile >> Current_String)
|
!infile.eof() will read in the last line of your file twice, which is a pain.
"infile >> Current_String" Actually evaluates to a bool expression while also functionally putting the next line form the file into the variable.
I personally have no idea whats going on here. It apears to me that theres alot of errors there.
1 2 3 4 5 6 7 8 9 10
|
int average;
while (!infile.eof())
{infile,array
//calculate if eligible
if (sales > average)
{
//bonus
bonus = sales - average;
}
|
First of all, You are trying to see if Sales is greater than average before average has any actual value.
Also, im not sure what your trying to do here with {infile,array
But moving on to your actual question...
This would be alot easier if you could put their name and their salery in different files, or atleast different lines.
But anyway, You would probably want to create 2 arrays. One for the empoyee names and another for the saleries. The names array would have to be a string array, and the salery array would have to be an integer array.
so something like this
1 2
|
int salary[100];
string names[100];
|
You would also want 2 int variables. One to keep track of how many galleries you have put in an array and another to keep a running total of the galleries. This way you can get your average without having to use another loop to sort through your arrays after youve gotten all the stuff from the file.
So you would probably want it to looks something like this
int ttl_saleries = 0;
int sum_of_saleries = 0;
From here you will need to have your while loop to get input from the file. However since the salleries and the names have to be in the same line im not really sure how you would go about splitting thos up, unless you can loop through a string character by character and after the second space add all characters to a new variable which would than be converted into an integer variable, and you could than put the name and the salery in different arrays.
When you have to figure out if someones salery is over the average you would use a for loop with your arrays.
1 2 3 4 5
|
int bonus;
for(i = 0; i<100, i++){
if(salary[i] >average){
bonus = (salary[i]-average)/.05);}
outfile << names[i] << " " << bonus << " "<< salary << endl;}
|
Hope this helps.