We want to track weather conditions during the past year and have designated each day as either

Rainy ('R')
Flooding ('F')
Cloudy ('C')
Sunny ('S')
Armegeddon ('A')
Write a program that stores this information in s 12x30 array of characters, where the row indicates the month and the column indicates the day of the month. Note no data is being captured for the 31st of any month since 31 is an unlucky number.

This program will read the data into the array from a file called RainOrShine.txt. From this data it you should create a report that displays, for each month, and for the whole twelve month period, how many days were of each type. It should also report the first month that had the largest number of sunny days (ties are ignored).

Remember that good correct functions are required too, you must pass the 2d array to a function!!

This is the text:
C A S C R C A A R S C S A S C R C C S C A S R A C S A A S A
C A R A S S R A C A A A R S S A R A A S A C R S C S A C R A
A A A S S A S S R S A R A C R A A A R C A R A R C A S C A S
S R S C A R A R R S A A S R A S S S C S S R S C S C C S A R
S C C C S A S A S C S A S C R A R S R R C C A C R R R C R S
R A A S C R R C S R R S S R R R S A S A R R A A C R R S C C
A A S C R S S A A C C S R R S R S C R S R A C C S R S C S C
S S S C A R C R R A R C S A A S C S R A A S A S S S S C C A
A R C A R C C S A C R A S R R C R R A A C S C C S S C R C C
C A A A A A S S S R S A R C S A C S R A A A C A R R S C C A
R R R C C A C C R R R S C R C A R C R R A C A S S C S S A S
S A S A C C S A C S R R C A C R R S A S C A R C S A C R C C

I also have my code:

#include <iostream>
#include <fstream>

using namespace std;

int main ()
{
    ifstream weather;
    weather.open("RainOrShine.txt");

    char sunshine[12][30];
    for(int j = 0; j < 12; j++)
    {
        char ch;
        for(int i = 0; i <= 30; i++)
        {
            weather.get(ch);
            if(ch == 32)
                break;

            else
                sunshine[j][i]= ch;
        }

    }
    string months[] = {"January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December"};
    int maxSunny = 0;
    string maxSunMonth = " ";
    cout << "\t" << "Rainy" << "\t" << "Flood" << "\t" << "Cloudy" << "\t" << "Sunny" << "\t" << "Armegeddon" << endl;

    for(int j = 0; j < 12; j++)
    {
        int rainy = 0;
        int flood = 0;
        int cloud = 0;
        int sunny = 0;
        int armegeddon = 0;

        for(int i=0; i < 30; i++)
        {
            if(sunshine[j][i] == 'C')
                cloud++;
            else if(sunshine[j][i] == 'R')
                rainy++;
            else if(sunshine[j][i] == 'S')
                sunny++;
            else if(sunshine[j][i] == 'A')
                armegeddon++;
            else if(sunshine[j][i] == 'F')
                flood++;
        }
        if(maxSunny < sunny)
        {
            maxSunny = sunny;
            maxSunMonth = months[j];

        }

        cout << months[j] << "\t" << rainy << "\t" << cloud << "\t" << sunny << "\t" << flood << "\t" << armegeddon << endl;

    }

    cout << endl << "The Sunniest month is: " << maxSunMonth << endl;

    return 0;
}

I cannot get the results and other part too

It looks to me you already failed the critical part of the exercise:

Remember that good correct functions are required too, you must pass the 2d array to a function!!

You should start with this. Read the data into the array and pass it to a function and process the array from there.

I think here map's are your friend. I would suggest a 2D map(map<string,map<string,int>>) for the monthly data and another(map<string,int>) for the yearly data. If necessary review the docs for map at the link.

commented: The cplusplus reference guide is invaluable, even for us experienced programmers! +14

Completely aside from the actual problem I would like to make two suggestions:

  1. Post programming questions in the programming forum
  2. Read the topmost thread titled Read This Before Posting A Question

If you had done that you would have chosen a more appropriate and informative title than "Help". The people here who provide the help do so voluntarily and a thread with an informative title is more likely to get a useful response than one without.

By the way, thanks for showing your code. A lot of people just post their homework and expect us to do it for them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.