Help with a C++ rainfall program

Anyone know what this error means or how to fix?

72 C:\Users\al\Documents\rainfall.cpp 'struct std::string' has no member named 'lowTemp'

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//Header file section
#include<iostream>
#include<string>
using namespace std;

struct weather
{
   double totalRainfall;
   double highTemp;
   double lowTemp;
   double avgTemp;
};

int main()
{
   weather months[12];
   double total =0, highest, lowest, avgsum;
   int highmonth, lowmonth;
   string month[12]= {"January", "February", "March", "April", "May", "June",
                       "July", "August", "September", "October", "November",
                       "December"};

   for(int i=0; i<12; i++)
   {
       cout<<"Enter total rainfall for month "<<month[i]<<": ";
       cin>>months[i].totalRainfall;

       cout<<"Enter high temperature: ";
       cin>>months[i].highTemp;

       while (months[i].highTemp < -100 || months[i].highTemp > 140)
       {
           cout<<"ERROR: Temperature must be in the range of "
           <<"-100 through 140.\n";
               cout<<"\tHigh Temperature: ";
               cin>>months[i].highTemp;
       }
       cout<<"Enter low temperature: ";
       cin>>months[i].lowTemp;

       while (months[i].lowTemp < -100 || months[i].lowTemp > 140)
       {
           cout<<"ERROR: Temperature must be in the range of "
           <<"-100 through 40.\n";
           cout<<"\tLow Temperature: ";
   //        cin>>month[i].lowTemp;
       }
   }
   //Calculate the monthly average temperature and total rainfall.
   for (int i=0; i<12; i++)
   {
       total=total + months[i].totalRainfall;
     //  months[i].avgTemp= (months[i].highTemp + month[i].lowTemp)/2;
   }

   highest=months[0].highTemp;
   lowest=months[0].lowTemp;

   for(int i=1; i<12; i++)
   {
       if(months[i].highTemp>highest)
       {
           highest=months[i].highTemp;
           highmonth=i;
       }
       if(months[i].lowTemp<lowest)
       {
           lowest=months[i].lowTemp;
           lowmonth=i;
       }
   }
   avgsum = 0;

   //Calculate the average.
   for(int i=0; i<12; i++)
   {
       avgsum=avgsum+months[i].avgTemp;
   }

   //Display the calculated data.
   cout<<"Average monthly rainfall: "<<total/12<<endl;
   cout<<"Total monthly rainfall: "<<total<<endl;
   cout<<"Highest rainfall in "<<month[highmonth]<<"is: "<<highest<<endl;
   cout<<"Lowest rainfall in "<<month[lowmonth]<<"is: "<<lowest<<endl;
   cout<<"Average of average temperatures is: "<<avgsum/12<<endl;

   system("pause");
   }
I think you used
month[i].lowTemp
instead of
months[i].lowTemp
You missed out the "s" at the end of "months". Let this be a lesson to you in variable naming practice :)
Topic archived. No new replies allowed.