c++ - How can I add items to the output file? -


i newbie c++ , i've got first assignment. we've got text file contains 5 employee names, wages, , hours worked.

and code program read it.

#include <iostream> #include <fstream> #include <iomanip> #include <string> #include <vector>  using namespace std;  int main() {     ifstream input;     ofstream output;      string name;     int h;     float w;     int numeployee = 0;     double maxpay, minpay, avgpay;     int gross, adjgross;      //input/output file document path     input.open("/users/jmduller/documents/xcode/lab1/lab1/employees.txt");     output.open("/users/jmduller/documents/xcode/lab1/lab1/employeesoutput.txt");      //checks if input file working     if (input.fail())     {         cout << "input file failed open." << endl;         system("pause");         exit(0);     }      //checks if output file working     if (output.fail())     {         cout << "output file failed open." << endl;         system("pause");         exit(0);     }      //prints name, wage, hours worked of employees output file     while (input >> name >> w >> h)     {         output << setw(5) << name << setw(5) << w << setw(5) << h << endl;     }     system("pause");   return 0; } 

it's reading , giving me output file want there missing items. complete output file should have number of employees, max pay, min pay, avg pay, gross pay, , adjusted gross.

can me point right direction?

thanks

what got use conditions , statements inside while loop statement (which reading file). increment 'numemployee' variable everytime loop executes(counts number of entries).

compare 'w' read check if lower than minpay(initialized large) update minpay otherwise if higher maxpay(intialized least value possible) update maxpay.

also, add 'w' variable sumpay(initialized zero) in loop , @ end divide numemployee , done. output them file before return statement.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -