Hmm, one more thing if anyone can figure this out. (I've been trying the past 30 minutes.) When my data is outputted, the updated salary is wrong. The output text file shows as:
Andrew Miller 1.8e-043
Sheila Green 1.8e-043
Amit Sethi 1.8e-043
Obviously, these salaries are wrong. Right now I'm just looking over my math and whatnot to see if I can figure this out, but if you have ideas let me know. Updated coded is below.
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
using namespace std;
bool getEmp (ifstream& empFile, string& lastName, string& firstName,
float& salary, float& raise);
void writeEmp (ofstream& newFile, string& firstName, string&lastName,
float& updatedSalary);
void calcSalary (float salary, float raise, float updatedSalary);
int main()
{
cout << "Beginning employee salary updation.\n";
ifstream empFile ("Ch3_Ex8Data.txt");
if (!empFile) {
cerr << "The system was unable to open the file."; //error if file is in use.
exit(100); //if it is, terminate.
}
ofstream newFile ("Ch3_Ex8Output.dat");
if (!newFile) {
cerr << "They system was unable to open the file.";
exit (102);
}
string firstName, lastName;
float salary, raise, updatedSalary;
while (getEmp (empFile, lastName, firstName, salary, raise))
{
calcSalary (salary, raise, updatedSalary);
writeEmp (newFile, firstName, lastName, updatedSalary);
} //end of while
empFile.close();
newFile.close();
cout << "End of salary updation.\n";
cout << salary;
return 0;
} //end of main
bool getEmp(ifstream& empFile, string& lastName, string& firstName,
float& salary, float& raise)
{
empFile >> lastName >> firstName >> salary >> raise;
if (!empFile)
return false;
return true;
} //end getEmp
void calcSalary(float salary, float raise, float updatedSalary)
{
updatedSalary = (salary * (1+ (raise/100)));
return;
} //end calcSalary
void writeEmp(ofstream& newFile, string& firstName, string& lastName,
float& updatedSalary)
{
newFile << setprecision(2) << firstName << "\t";
newFile << lastName << "\t";
newFile << updatedSalary << "\n";
return;
} //end writeEmp
edit i changed the setprecision line to this
Code:
newFile << fixed << setprecision(2) << firstName << "\t";
Now sci-notation is gone, but the numbers are still wrong.