|
From: Per W. <pw...@ia...> - 2008-02-29 16:09:24
|
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;
> }
>
|