I have a text file that I am reading into my program. The data looks as follows:

Last Name, First Name, Current Salary, Raise Percentage

iller Andrew 65789.87 5
Green Sheila 75892.56 6
Sethi Amit 74900.50 6.1
Ge Robert 81990.23  3.3
Smith David 43221.33  5.5
Jones Mary 33345.12  2.3
Goodman Bill 67845.67 3.5

Attached is the code, and I am unable to do the calculation

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[])
{
 double employeeSalaryRaises[100];
 double employeeSalaries[100];
 string employeeFirstNames[100];
 string employeeLastNames[100];
 int counter;

   double salary;
   string firstName;
   string lastName;
   double raise;
   double updatedSalary;

   ifstream  inFile;
   ofstream outFile;
   inFile.open("Ch5_Ex2Data.txt");
   outFile.open("Ch5_Ex2Output.txt");
//   int i;
   counter = 0;


//check to ensure there is a valid input file
if (!inFile)
{
                  cout << "Input file failed." << endl;
                  cout << "Program Terminates!!!" << endl;
                  cout << " " << endl;

                  system ("PAUSE");
                  return 1;
}


while (!inFile.eof())
{
   inFile >> employeeLastNames[counter] >> employeeFirstNames[counter] >> employeeSalaries[counter] >>  employeeSalaryRaises[counter];

   counter = counter + 1;
; 
}




string temp;
int index;
int i;


  for(i=0; i< counter; i++)
  {
           for (index =0; index < counter -i -1; index++)
           {
               if ( employeeLastNames [index] < employeeLastNames [index + 1])
               {
                    temp = employeeLastNames[index];
                    employeeLastNames[index] = employeeLastNames[index +1];
                    employeeLastNames[index +1] = temp;
                    }
                    }
}


for (i=0; i<counter; i++)
{
updatedSalary = employeeSalaries * employeeSalaryRaises  /100; 


         outFile << fixed << showpoint; 
         outFile << setprecision(2);                    
         outFile << "Record " << i << ":" << updatedSalary << " " << endl;

         cout << fixed << showpoint;
         cout << setprecision (2);           
         cout << "Record " << i << ":" << updatedSalary << " " << endl;

  }  
    system("PAUSE");
    return EXIT_SUCCESS;
}

The output should look as follows after running the program...

Record 0:33345.1
Record 1:43221.3
Record 2:65789.9
Record 3:67845.7

and so on..

1) Please use code tags when posting code - it makes it much easier for us to read.

2) I suggest you "break out" the problem. That is, create a new program that sets up some hard coded values and tries to do the computation. You should then have only a few lines to deal with and will likely be able to find the problem. If not, you can ask us and we only have to look at the few relevant lines rather than wondering if there is a problem with your input routines, etc.

David

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.