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!!
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;
}