ok I got this far with the code and still end of with 16 errors.
#include <iostream> // standard IO routines
#include <iomanip> // for output formatting
#include <fstream> // standard file stream
#include <cmath> // standard math functions
#include <string> // standard C++ library
using namespace std; // standard C++ namespace
//define the structure
struct WEATHER
{
double totalRainfall;
double highTemp;
double lowTemp;
double avgTemp;
};
// Function Prototypes
void getdata(WEATHER&); // Argument passed by reference
//month months[12];
int main()
{
//declare array of structures
WEATHER annualWeather[12];
getdata(annualWeather[]); //call the function pass the argument to the function
double AnnualRainfall; // declare variable
for(int x = 0; x < 11; x++)
AnnualRainfall += annualWeather.totalRainfall[i];
cout << " Total Rainfall is" AnnualRainfall << endl;
return 0;
}
void getdata(WEATHER annualWeather[i]&) //annual weather is the reference parameter
{
int i;
double MaxHighTemp = 0;
double MaxLowTemp = 10000;
for(i=0;i<12;i++)
{
cout << "enter low tempature for month " i + 1 << ":" << endl;
cin >> annualWeather.lowTemp[i];
while(annualWeather.lowTemp[i] < -100)
{
cout << " must be gretaer than -100 " << endl;
cin >> annualWeather.lowTemp[i];
}
if (annualWeather.highTemp[i] < lowHighTemp)
MaxLowTemp = annualWeather.lowTemp[i];
cout << "enter high tempature for month " i + 1 << ":" << endl;
cin >> annualWeather.highTemp[i];
while(annualWeather.highTemp[i] < -100)
{
cout << " must be less than 140 " << endl;
cin >> annualWeather.highTemp[i];
}
if (annualWeather.highTemp[i] > MaxHighTemp)
MaxHighTemp = annualWeather.highTemp[i];
cout << "enter total rainfall for month " i + 1 << ":" << endl;
cin >> annualWeather.totalRainfall[i];
annualWeather[i].avgTemp = (annualWeather[i].lowTemp + annualWeather[i].highTemp) / 2;
}
}
below is the error log that i received.
1>------ Build started: Project: lab9, Configuration: Debug Win32 ------
1>Compiling...
1>lab9.cpp
1>c:\users\arron\desktop\lab9\lab9\lab9.cpp(36) : error C2059: syntax error : ']'
1>c:\users\arron\desktop\lab9\lab9\lab9.cpp(41) : error C2228: left of '.totalRainfall' must have class/struct/union
1> type is 'WEATHER [12]'
1>c:\users\arron\desktop\lab9\lab9\lab9.cpp(41) : error C2065: 'i' : undeclared identifier
1>c:\users\arron\desktop\lab9\lab9\lab9.cpp(43) : error C2146: syntax error : missing ';' before identifier 'AnnualRainfall'
1>c:\users\arron\desktop\lab9\lab9\lab9.cpp(43) : error C2563: mismatch in formal parameter list
1>c:\users\arron\desktop\lab9\lab9\lab9.cpp(43) : error C2568: '<<' : unable to resolve function overload
1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(974): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=wchar_t,
1> _Traits=std::char_traits<wchar_t>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(966): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(940): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1>c:\users\arron\desktop\lab9\lab9\lab9.cpp(47) : error C2065: 'i' : undeclared identifier
1>c:\users\arron\desktop\lab9\lab9\lab9.cpp(47) : error C2143: syntax error : missing ',' before '&'
1>c:\users\arron\desktop\lab9\lab9\lab9.cpp(56) : error C2146: syntax error : missing ';' before identifier 'i'
1>c:\users\arron\desktop\lab9\lab9\lab9.cpp(56) : warning C4554: '<<' : check operator precedence for possible error; use parentheses to clarify precedence
1>c:\users\arron\desktop\lab9\lab9\lab9.cpp(56) : error C2297: '<<' : illegal, right operand has type 'const char [2]'
1>c:\users\arron\desktop\lab9\lab9\lab9.cpp(56) : error C2563: mismatch in formal parameter list
1>c:\users\arron\desktop\lab9\lab9\lab9.cpp(56) : error C2568: '<<' : unable to resolve function overload
1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(974): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=wchar_t,
1> _Traits=std::char_traits<wchar_t>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(966): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\ostream(940): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1>c:\users\arron\desktop\lab9\lab9\lab9.cpp(57) : error C2228: left of '.lowTemp' must have class/struct/union
1> type is 'WEATHER []'
1> did you intend to use '->' instead?
1>c:\users\arron\desktop\lab9\lab9\lab9.cpp(58) : error C2228: left of '.lowTemp' must have class/struct/union
1> type is 'WEATHER []'
1> did you intend to use '->' instead?
1>c:\users\arron\desktop\lab9\lab9\lab9.cpp(58) : fatal error C1903: unable to recover from previous error(s); stopping compilation
1>Build log was saved at "file://c:\Users\Arron\Desktop\lab9\lab9\Debug\BuildLog.htm"
1>lab9 - 15 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========