How would i display the total sum in one cout rather than individual ones?

So i have 98% of my code done, but im coming across an issue where instead of one total sum, i'm getting five individual ones. How would i go about just getting one total? My assignment is getting the total payroll of 5 different employees which are in the form of a text file. For reference Text code is:

123-45-6789,Linda Smith,50, 10.00, 133-56-7890,Carol Melville,35,12.50, 167-33-4589,Marilyn Lloyd,42,16.00, 156-90-5432,Joyce Davis,27,11.25, 195-56-9000,Susan Cook, 49,12.00

This is the actual program:

#include <iostream> #include <iomanip> #include <fstream> #include <string> using namespace std; struct incomeInfo { string id; string name; int hours; double hRate; double regPay = 0; double otPay = 0; }; const int ARRAY_SIZE = 25; // Array size incomeInfo income[ARRAY_SIZE]; // array variable declaration void getIncome(incomeInfo[], int&); void compute(incomeInfo *, int); void display(incomeInfo[], int); void summary(incomeInfo[], int); int main() { incomeInfo income[ARRAY_SIZE]; int count = 0; //Initialize count to 0 getIncome(income, count); compute(income, count); display(income, count); summary(income, count); return 0; } void getIncome(incomeInfo income[], int &count) { string name; char line[50]; // Variable to read data // Open data File to read data ifstream inputFile; string fileName; int value; cout << "Please enter the path name where payroll.txt is located (Check the HW5 folder): "; getline(cin, fileName); // Open the file inputFile.open(fileName.c_str()); // test if data file opened incorrectly if (inputFile.fail()) { cout << "\n\n\tError openning file." << "\n\n\t"; system("pause"); exit(1); } else { while (!inputFile.eof()) //Check end of file { inputFile.getline(line, 50, ','); // The data are separated by comma income[count].id = line; inputFile.getline(line, 50, ','); income[count].name = line; inputFile.getline(line, 50, ','); income[count].hours = atoi(line); // Convert string to integer inputFile.getline(line, 50, ','); income[count].hRate = atof(line); // Convert string to float count++; } } inputFile.close(); return; } void compute(incomeInfo *ptrI, int count) { for (int i = 0; i<count; i++) { if (ptrI->hours <= 40) { ptrI->regPay = ptrI->hours * ptrI->hRate; ptrI++; } else if (ptrI->hours > 40) { //ptrI->regPay = ptrI->hours * ptrI->hRate; ptrI->regPay = 40 * ptrI->hRate; ptrI->otPay = (ptrI->hours - 40) * (ptrI->hRate + (ptrI->hRate* .5)); ptrI++; } } return; } void display(incomeInfo income[], int count) { cout << fixed << showpoint << setprecision(2); cout << setw(15) << left << "ID" << setw(16) << "Name"; cout << left << setw(8) << "Hours" << setw(14) << "Hourly Rate" << setw(14) << "Regular Pay" << setw(14) << "Overtime Pay" << endl; for (int i = 0; i < count; i++) { cout << setw(14) << left << income[i].id << setw(15) << income[i].name; cout << right << setw(6) << income[i].hours << setw(12) << income[i].hRate; cout << setw(14) << income[i].regPay << setw(14) << income[i].otPay << endl; } return; } void summary(incomeInfo income[], int count) { for (int i = 0; i < count; i++) cout << endl << endl << "Total payroll amount for the company = " << income[i].regPay + income[i].otPay << endl; system("PAUSE"); }

Category:c# Time:2018-12-23 Views:3
Tags:

Related post

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.614 (s). 13 q(s)