0

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..

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by daviddoria
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.