returning values to main

I am working on this program below. The problem I am having is trying to return totalDays to the main. In the numOfDays() function there is a for loop that adds the totalDays (totalDays = totalDays + days). I have just been getting errors in returning the correct amount of totalDays to the main from the numOfDays function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
using namespace std;

int numOfEmployees();

int numOfDays(int);

int main()
{ 
 int totalDays = 0;
 int employNum;
 int amountSick;

 employNum = numOfEmployees();
 amountSick = numOfDays(employNum);
 
 cout << amountSick;
}

	int numOfEmployees()
	{
		int employees;
		
		cout << "How many employees? ";
		cin  >> employees;
		
		return employees; 
	}
	
	int numOfDays(int employees)
	{   
	    int num = 1;
	    int totalDays = 0;
		
        for (employees; employees > 0; employees --)
         {  
            int days;
            int totalDays = 0;
            
         	cout << "How many days has employee " <<num<< " been sick? ";
         	cin >> days;
         	
         	totalDays = totalDays + days;
         	num ++;
         }
         
         return totalDays;
	}
Last edited on
You have TWO int totalDays.
Remove the one inside the for loop: it's aliasing the other one.
thanks
Topic archived. No new replies allowed.