C++ sum of values in loop

Hi, I am done with my code with no debugging errors. However, the program does not work the way it should. This program is designed to ask for the number of sick days for multiple employees, find the sum of sick days for each employee, then find the TOTAL number of sick days for all employees. The issue is the last statement. When it should be outputting the total sick days for all staff, it only outputs the total number of sick days for the last employee entered. Please help!


//This program will calculate the number of sick days used by library employees

#include <iostream>
#include <string>
using namespace std;

int main()
{
float sickdays, sickdaysYear1, sickdaysYear2, sickdaysYear3, sickdaysYear4, employeeTotalsickDays, total;
int numEmployees = 0; //counter for loop
string employeeName;



cout << "This program will find the number of sick days of library employees." << endl;
cout << "How many employees are at the library?" << endl;
cin >> numEmployees;


for (int i=1; i<=numEmployees; i++)
{
total = 0;


cout << "Please enter the name of employee #" << i << endl;
cin >> employeeName;

cout << "How many days was " << employeeName << " sick from work in 2012" << endl;
cin >> sickdaysYear1;
cout << "How many days was " << employeeName << " sick from work in 2013" << endl;
cin >> sickdaysYear2;
cout << "How many days was " << employeeName << " sick from work in 2014" << endl;
cin >> sickdaysYear3;
cout << "How many days was " << employeeName << " sick from work in 2015" << endl;
cin >> sickdaysYear4;

employeeTotalsickDays = sickdaysYear1 + sickdaysYear2 + sickdaysYear3 + sickdaysYear4;
;
cout << endl;
cout << employeeName << " has had " << employeeTotalsickDays << " sick days in the past four years." << endl;
total+=employeeTotalsickDays;

}


cout << "In the past four years, the library employees have had " << total << " sick days." << endl;
return 0;
}
You are resetting total to zero inside the loop.
Thank you!! I knew it had to be a simple error. Must have overlooked it
Topic archived. No new replies allowed.