Hey, basically I'm trying to use a function to manipulate data stored within a struct, then return a double created with that data.
I believe that the problem occurs at line 37. Basically, I'm collecting a bunch of values into weather[i].totalRain, then using the function rainSum() to add up all of the values, then returning them as the double rainSum. Does the problem lay in the way I'm sending data to the function, or the way I'm calling it? I've looked all throughout my notes, text, and online for some sample code but I've just started using structs and I haven't been able to come up with anything relevant. Thanks in advance!
Note: This program will not compile unless I remove line 37 currently.
#include <iostream> #include <string> using namespace std; struct WEATHER { double totalRain, highTemp, lowTemp; }; enum Month { JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER }; double rainSum(WEATHER); double averageRain(WEATHER); double averageTemp(WEATHER); double highestTemp(WEATHER); double lowestTemp(WEATHER); const int NUM_MONTHS = 12; int main() { WEATHER weather[NUM_MONTHS]; for (int i=0; i<3; i++) { cout << "Month " << (i+1) << endl << "\tTotal Rainfall: "; cin >> weather[i].totalRain; cout << endl << "\tHigh Temperature: "; cin >> weather[i].highTemp; cout << endl << "\tLow Temperature: "; cin >> weather[i].lowTemp; } cout << endl << endl << "Total Rainfall: " << rainSum(weather[NUM_MONTHS]) << endl; system ("pause"); return 0; } double rainSum(WEATHER weather[NUM_MONTHS]) { double rainSum; for (int i=0; i<NUM_MONTHS; i++) { rainSum = (weather[i].totalRain)+rainSum; } return rainSum; }
I believe that the problem occurs at line 37. Basically, I'm collecting a bunch of values into weather[i].totalRain, then using the function rainSum() to add up all of the values, then returning them as the double rainSum. Does the problem lay in the way I'm sending data to the function, or the way I'm calling it? I've looked all throughout my notes, text, and online for some sample code but I've just started using structs and I haven't been able to come up with anything relevant. Thanks in advance!
Note: This program will not compile unless I remove line 37 currently.