C++ Learning Community Forum
September 11, 2010, 02:06:31 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Hello. Smiley
 
   Home   Help Search Login Register  
Poll
Question: arrays are easy to understand?  (Voting closed: March 25, 2007, 02:03:10 PM)
a - 2 (100%)
b - 0 (0%)
Total Voters: 2

Pages: [1]
  Print  
Author Topic: arrays -- HELP  (Read 405 times)
abcdefg
N00b!!1
*
Posts: 14


View Profile
« on: March 24, 2007, 01:03:10 PM »

Hi,

When I was reading a book about arrays in C++, I  got a doubt about how we should create a report .

In other words, if the problem is like  a metrologist wants to keep track of the 3 seasons in the last year, whether they are sunny, rainy or cloudy.

Then I took a 3 x 30 array. (He doesn't want to record the 31st of any month)

3 -->  months --> June, July,August.
30 --> days. (1,2,3-------30)

The data is being read by a .dat file.

Then the program 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 3 months
 had the largest number of rainy days.

I got blank when I saw creating a report. Can some one please....please explain me how can I go further in my program.

Thanks......
Logged
shikyo
Jr. Nerd
***
Posts: 68



View Profile
« Reply #1 on: March 24, 2007, 01:45:07 PM »

Post what code you've come up with so far, and it will be easier to understand and help you.
Logged
zaqufant
Farmer Brown
Dr. of C++ology
****
Posts: 963


Harder, better, faster, stronger.


View Profile
« Reply #2 on: March 24, 2007, 05:33:36 PM »

Are you perhaps trying to acess an element in the array that doesn't exist?
Logged
abcdefg
N00b!!1
*
Posts: 14


View Profile
« Reply #3 on: March 25, 2007, 01:22:03 PM »

This is my code so far. The out put is , the data from the .dat file.
Code:
#include <iostream>
#include<fstream>
#include<string>


using namespace std;

int main()
{   
      char NUM_MONTHS  = 3;
    // string name[NUM_MONTHS] = {"June","July","August");
      char NUM_DAYS = 30;
     char rainorshine [NUM_MONTHS][NUM_DAYS];
     int month ,count ;
     ifstream datafile;
     datafile.open("RainOrShine.dat");
     if (!datafile)
      cout<<"Error";
      else
      {
         cout<<" This is the data for June, July, August. "  << endl<<endl;
          cout<< "MONTH 0 = JUNE,MONTH 1 = JULY, MONTH 2 = AUGUST"<< endl<<endl;
         for(month = 0; month < NUM_MONTHS ; month++)
          { for (count =0; count < NUM_DAYS ; count++)
              {
                       cout << " MONTH " <<(month)
                            << ",DAY " << (count+1) << " : ";
                      datafile >> rainorshine[month][count];
                      cout << rainorshine[month][count] << endl;
                       }
              cout<<endl;
              }
              }
The output is like this:
Code:
MONTH 0, DAY1 : S
.........................              // MONTH 0 means JUNE.
.........................
.........................
MONTH 0, DAY 30 : C

MONTH 1, DAY1 : R
.........................
.........................           //MONTH 1 means JULY
.........................
MONTH 1, DAY 30 : S

MONTH 2, DAY1 : S
.........................
.........................               //MONTH 2 means AUGUST
.........................
MONTH 2, DAY 30 : C

From now what I need to find out is 1.how many rainy, cloudy, sunny days in each month and whole 3 month period?
2. which of the 3 months had the largest number of rainy days.




« Last Edit: March 31, 2007, 07:34:40 AM by myork » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!