adding values returned from functions

I am trying to create a series of fuctions for the 4 weeks in a month that will return the average length of a workout. My problem is I don't know how to call on these values that the functions are returning so that I can add them together.This is the code I am using to calculate the average from each day but now I need to know how to access the value returned on line 41 while I am in another function or in main. Please help!!

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
int calculate_week_one()
{
    int num_days; 
    float average; 
    float total=0; 
    float length;
    int counter =1; //typical counter 
    
    cout<<"How many times this week did you exercise?"<<endl;
    cin>>num_days;
    cin.get();
    
    
    
     if(num_days<=0||num_days>7)  //Makes sure the input is valid
   {
       cout<<"The number you have entered is unreasonable";
       cout<<endl<<"Try Again!"<<endl;
       cout<<"How many times this week did you exercise?"<<endl;
       cin>>num_days;
       cin.get();
   }
                         
    else
       cout<<"We are ready to work on calculating the average length of your work out"<<endl;
        
   do   
   {       
       cout<<"Please enter the length of time spent exercising on the "<<counter<<" day"<<endl;
       cin>>length;
    
       ++counter;
       total += length;

   }while(counter<=num_days);
    
    average = total/num_days;
    
    cout<<"Your average for this week is"<<average<<" minutes long"<<endl;
    cin.get();
    return average;
    
}
1
2
3
4
5
6
7
int week1 = calculate_week_one();
int total = week1 + calculate_week_two();

// or
int total = calculate_week_one() + calculate_week_two();

//etc 
Topic archived. No new replies allowed.