An amateur meteorologist wants to keep track of weather conditions during the past year's three month summer
season and has designated each day as either rainy(R), cloudy (C) or sunny (S). Write a program that stores this information in a 3x30 array of characters, where the row indicates the month (0=june,1=july,2=August) and the column indicates the day of the month. Note that data is not being collected for the 31st of any month. The program should begin by reading the weather data in from a file. Then it should create a report that displays for each month and for the whole 3 month period, how many days were rainy, how many were cloudy, and how many were sunny. It should also report which of the three months had the largest number of rainy days. Data for the program can be found in rainorshine.dat file.


The data file says:


RRCSSSCSCRRRCSSSCSSRSCCRCRRCSS
SSSCCSSSCCSSSCCSSSCRCRCCSSSSSS
SSSSCSSSCSSSCRRCCCSSSSSCSSSSCS

i would like help setting up this program... I am looking for the comments... I don't want you to do it for... or anything like that... I just need to be started off.. we haven't covered this chapter in class yet....

Which chapter would that be? Of course there is nothing wrong with you reading the chapter yourself.

The instructions seem pretty clear to me

  1. Create the starter program with main() function
  2. Add a character array that has 3 rows and 30 columns
  3. Create an iostream object, open the data file and read the rows into the array.
  4. Loop through the character array and, for each month, count the number of R's, S's and C's.
  5. Display the report on the screen using std::cout.

If you don't know how to use ifstream then you can search for example code -- there is lots of it all over the net and even here at DaniWeb. Learn to make google one of your best programming buddies.

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    const int NUM_MONTHS = 3;
    const int NUM_DAYS = 30;
    const int NUM_TYPES= 3;
    char forecast[NUM_MONTHS][NUM_DAYS];
    int counts [NUM_MONTHS][NUM_TYPES];
    int rainyDays = 0;

    ifstream datafile;
    
    datafile.open("RainOrShine.txt");
    if (!datafile)
        cout << "Error opening data file.\n";
    else
    {

        // Read data and load arrary
        
        for(int month = 0; month < NUM_MONTHS; month++)
        { 
            for(int day = 0; day < NUM_DAYS; day++)
        
            {
                datafile >> forecast[month][day];
                
            }
            datafile.ignore();
        }
        
        for(int month = 0; month < NUM_MONTHS; month++)
        { 
            for(int day = 0; day < NUM_DAYS; day++)
        
            {
                cout << forecast[month][day] << '\t';
                
            }
            cout << endl;
        }        
        
        
    // intialize counts arrarys to 0
        
        for(int month = 0; month < NUM_MONTHS; month++)
        { 
            for(int type = 0; type < NUM_TYPES; type++)
        
            {
                counts[month][type] =0;
                
            }
            
        }
        
     // count all data   
        
        for(int month = 0; month < NUM_MONTHS; month++)
        { 
            for(int day = 0; day < NUM_DAYS; day++)
            {
         
                  if(forecast [month][day] =='R')
                  {
                        counts[month][0]++;
                  }      
                           
                  if(forecast [month][day] =='S')
                  {
                        counts[month][1]++;
                  }
                  
                     
                  if(forecast [month][day] =='C')
                  {
                        counts[month][2]++;
                  }
      
            }
            
        }

        
        

        for(int month = 0; month < NUM_MONTHS; month++)
        { 
            for(int type = 0; type < NUM_TYPES; type++)
        
            {
                cout << counts[month][type] << '\t';
                
            }
            cout << endl;
        }
  
      
        
  
      
      // Determine month with largest number of rainy days
      
      
      
      
        
        
      // output report  
      
    cout << "Three-Month Analysis\n\n";      
        
  
  
        
        
    }
    
    
    system("pause");
    return 0;
  
}

How do i find the month with the largest amount of rain?

>>How do i find the month with the largest amount of rain?
You already have the array that contains the count of the number of Rs, Ss and Cs. Now all you have to do is iterate through that array and keep track of which month has the greatest number of Rs. How would you do that? Try it with pencil & paper first

This article has been dead for over six months. Start a new discussion instead.