|
From: Shawn <tre...@gm...> - 2008-02-29 22:12:42
|
It's just going to be a list of the months that the code in the for loop
will iterate thru...string data. When they enter one for the outside
loop of the year, it will goto the inside loop and each time the loop
asks for the average rainfall, I want it to start for Jan, next prompt
for Feb, taken directly for the array I'm trying to initialize.
Thanks.
Per Westermark wrote:
> You must have missed something in your C++ book. Class of what type? And
> if you try to get an array of January, February, ... - where is the
> definition for January?
>
> char* months[] = { "January", "February", ... };
>
> In this case, months has a known data type - array of string pointers.
> In this case, the array elements are not undefined variables, but of
> directly specified string constants.
>
> /pwm
>
> On Fri, 29 Feb 2008, Shawn wrote:
>
>
>> I've never tried using arrays before in C++, just am familiar with using
>> them in python. I tried initializing the array as string months and
>> then {"January","February", ect} but the complier told me I needed to
>> set it up in constructor method. I looked that up in my book and came
>> up with this, but now I get the error that January isn't declared.
>>
>> My intention is to have it automatically advance to the next month in
>> the list by months[i] in the inner loop. Am I on the right track?
>>
>> Thanks!
>>
>> #include<iostream>
>> #include<iomanip>
>> using namespace std;
>>
>>
>>
>> int main()
>> {
>>
>> int years = 0;
>> int counter = 0;
>> int month = 0;
>> int average = 0;
>> *class months =
>> {January,February,March,April,May,June,July,August,September,October,November,December};*
>>
>>
>> months++
>> cout<<"Please enter the # of years.">>endl;
>> for(i=years; i<=years; i++1)
>>
>> {
>> for(i=12; i<=12; i++1)
>> {cout<<"Please enter the rainfall for"<<months[i]<<;
>> cin>>month
>> sum = sum + month
>> counter = counter + 1
>> }
>>
>> average = sum / counter
>>
>>
>> cout<<"The total number of months was "<<counter<<".";
>> cout<<"The total inches of rainfall was "<<sum<<".";
>> cout<<"The average rainfall was "<<average<<".";
>>
>>
>>
>> return 0;
>> }
>>
>>
>
>
>
|