Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Summary Three employees in a company are up for a special pay increase. You

ID: 3755480 • Letter: C

Question

C++

Summary

Three employees in a company are up for a special pay increase. You are given a file, say Ch3_Ex5Data.txt, with the following data:

Each input line consists of an employee’s last name, first name, current salary, and percent pay increase.

For example, in the first input line, the last name of the employee is Miller, the first name is Andrew, the current salary is 65789.87, and the pay increase is 5%.

Instructions

Write a program that reads data from the specified file and stores the output in the file Ch3_Ex5Output.dat.

For each employee, the data must be output in the following form: firstName lastName updatedSalary.

Format the output of decimal numbers to two decimal places.

This is what I have but the output file only has zeros "0.00"

#include <iomanip>

using namespace std;

int main()
{
string lastnameA, firstnameA;
double currentSalaryA,percentPayIncreaseA, updatedSalaryA;

string lastnameB, firstnameB;
double currentSalaryB,percentPayIncreaseB, updatedSalaryB;

string lastnameC, firstnameC;
double currentSalaryC,percentPayIncreaseC, updatedSalaryC;

ifstream inFile;
ofstream outFile;
inFile.open("Ch3_Ex7Data.txt");
outFile.open("Ch3_Ex7Output.dat");
outFile << setprecision(2) << showpoint << fixed;

inFile >> lastnameA >> firstnameA >> currentSalaryA >>
percentPayIncreaseA;

inFile >> lastnameB >> firstnameB >> currentSalaryB >>
percentPayIncreaseB;

inFile >> lastnameC >> firstnameC >> currentSalaryC >>
percentPayIncreaseC;

updatedSalaryA = currentSalaryA + (currentSalaryA * percentPayIncreaseA / 100);
updatedSalaryB = currentSalaryB + (currentSalaryB * percentPayIncreaseB / 100);
updatedSalaryC = currentSalaryC + (currentSalaryC * percentPayIncreaseC / 100);

outFile << lastnameA << " " << firstnameA << " " << updatedSalaryA <<endl;
outFile << lastnameB << " " << firstnameB << " " << updatedSalaryB <<endl;
outFile << lastnameC << " " << firstnameC << " " << updatedSalaryC <<endl;

inFile.close();
outFile.close();
return 0;
}

Explanation / Answer

You are getting 0.00 because your program is reading the wrong file.

Your inFile is Ch3_Ex5Data.txt, but your program is reading Ch3_Ex7Data.txt as inFIle

corrected code is:( look for bold line, which is edited by me)

********************************************************************

#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
string lastnameA, firstnameA;
double currentSalaryA,percentPayIncreaseA, updatedSalaryA;

string lastnameB, firstnameB;
double currentSalaryB,percentPayIncreaseB, updatedSalaryB;

string lastnameC, firstnameC;
double currentSalaryC,percentPayIncreaseC, updatedSalaryC;

ifstream inFile;
ofstream outFile;
inFile.open("Ch3_Ex5Data.txt"); //edited from inFile.open("Ch3_Ex7Data.txt");
outFile.open("Ch3_Ex5Output.dat");//
edited from outFIle.open("Ch3_Ex5Output.dat");
outFile << setprecision(2) << showpoint << fixed;

inFile >> lastnameA >> firstnameA >> currentSalaryA >>
percentPayIncreaseA;

inFile >> lastnameB >> firstnameB >> currentSalaryB >>
percentPayIncreaseB;

inFile >> lastnameC >> firstnameC >> currentSalaryC >>
percentPayIncreaseC;

updatedSalaryA = currentSalaryA + (currentSalaryA * percentPayIncreaseA / 100);
updatedSalaryB = currentSalaryB + (currentSalaryB * percentPayIncreaseB / 100);
updatedSalaryC = currentSalaryC + (currentSalaryC * percentPayIncreaseC / 100);

outFile << lastnameA << " " << firstnameA << " " << updatedSalaryA <<endl;
outFile << lastnameB << " " << firstnameB << " " << updatedSalaryB <<endl;
outFile << lastnameC << " " << firstnameC << " " << updatedSalaryC <<endl;


inFile.close();
outFile.close();
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote