I am trying to do a basic program that reads from a txt file and ouputs the results in a specific order on the screen. Its a salary type program.
Here is my salary.txt file
Randall Jones 25645.88 1999
Jim Johnson 56709 1992
Carol Troth 42387.05 2000
Briannal Deweyage 12567.99 2004
Bob Hoskins 76534.00 2002
Sonny Thomas 100000 1983
Susan Sarandon 1645.21 1981
Jamie Trance 44765. 1997
Kellie Whisk 54321.00 1993
Katie Turnerty 99.99 1979
Here is my salary.cpp file
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
ifstream myFile;
double salary, totalSalary=0;
string firstName, lastName, yearHired, fullName;
myFile.open("salary.txt");
cout<<fixed<<showpoint<<setprecision(2);
myFile>>firstName>>lastName;
while(!myFile.eof())
{
myFile>>firstName>>lastName>>salary>>yearHired;
fullName = lastName + ", " + firstName;
cout<<setw(10)<<fullName<<setw(10)<<salary<<setw(10)<<yearHired<<endl;
totalSalary += salary;
myFile>>firstName>>lastName>>salary>>yearHired;
}
cout<<endl<<setw(10)<<setfill('=')<<totalSalary<<endl;
if(salary >= 50000)
{
cout<<"*";
}
myFile.close();
return 0;
}
I am trying to get the results of putting those two programs together to output this screen:
Name Salary Hired
===============================
Jones, Randall $ 25645.88 1999
Johnson, Jim $ 56709.00 1992*
Troth, Carol $ 42387.05 2000
Deweyage, Briannal $ 12567.99 2004
Hoskins, Bob $ 76534.00 2002*
Thomas, Sonny $100000.00 1983*
Sarandon, Susan $ 1645.21 1981
Trance, Jamie $ 44765.00 1997
Whisk, Kellie $ 54321.00 1993*
Turnerty, Katie $ 99.99 1979
===============================
Total Salary ********* $414675.12
In summary, what im trying to do is to implement the program and output the lastName first, then the firstName... then have all of the salary numbers line up according to the decimal point with two decimal points to the right...and output all the years of the dates hired. then at the end of the program, add all of the salaries together, and output the final results. It seems like a relatively easy program, and my program compiles, but it shows this:
1999, 25645.88-71319654623666479083774548546739424319273737775962062297671976791828718398891937412147005776399452111478761517538510862556217750430449474153312582057515939921969392187159892407934170908216628314512097129276284689494211281475324122213783290655497100314044815979566684971355260584574063554057855540473626624.00
1999, 25645.88-71319654623666479083774548546739424319273737775962062297671976791828718398891937412147005776399452111478761517538510862556217750430449474153312582057515939921969392187159892407934170908216628314512097129276284689494211281475324122213783290655497100314044815979566684971355260584574063554057855540473626624.00
1999, 25645.88-71319654623666479083774548546739424319273737775962062297671976791828718398891937412147005776399452111478761517538510862556217750430449474153312582057515939921969392187159892407934170908216628314512097129276284689494211281475324122213783290655497100314044815979566684971355260584574063554057855540473626624.00
1999, 25645.88-71319654623666479083774548546739424319273737775962062297671976791828718398891937412147005776399452111478761517538510862556217750430449474153312582057515939921969392187159892407934170908216628314512097129276284689494211281475324122213783290655497100314044815979566684971355260584574063554057855540473626624.00
and those numbers keep going on and on...
It seems to be stuck on the first numbers given in my salary.txt file, and i have spent about 2 hours plugging in new things and taking things out, but still with the same result.
thanks for all your help