struct Month {
string month;
float avg;
};
float calMonth1() {
float sum;
int i;
Month month1;
//month 1
cout << "Weekly Dengue Case for Month of: ";
cin >> month1.month;
int n = 4;
int * week = new int[n];
for (i = 0; i < n; ++i) {
cout << "Week " << i + 1 << ": ";
cin >> week[i];
sum += week[i];
}
month1.avg = sum / i;
int firstWeek = week[0];
cout << "Average for " << month1.month << ": " << month1.avg;
return month1.avg;
}
float calMonth2() {
int i;
float sum;
Month month2;
//month 2
cout << "Weekly Dengue Case for Month of: ";
cin >> month2.month;
int n = 4;
int * week = new int[n];
for (i = 0; i < n; ++i) {
cout << "Week " << i + 1 << ": ";
cin >> week[i];
sum += week[i];
}
month2.avg = sum / i;
cout << "Average for " << month2.month << ": " << month2.avg;
return month2.avg;
}
int main() {
int firstWeek;
calMonth1();
calMonth2();
cout << "\nInformation for first week of January, total of " << firstWeek << " cases:\n";
return 0;
}
This is my code. What i want to do is to use firstWeek in the calMonth1 function into my main function. How can i possibly do that? I want to use only the first value of the array in calMonth1.
Example output:
Week 1: 10 Week 2: 20 Week 3: 30 Week 4: 40
Information for first week of January, total of 10 cases:
I would only want the value for the first week to display it in the above message. Thank you