| | |
Rain or shine help!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 57
Reputation:
Solved Threads: 0
I am supposed to be working on this problem that stores info in a 2x20 array of characters where the row indicates the month and the column indicates teh day. We have to read in from a file and then create a report that displays for each month and for the whole 2 month period..how many days were rainy, cloudy, and sunny. It also has to report which month had the largest num of rainy days...here's what i have so far:
can someone please help me to go in the right direction? I really appreciate it
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
const int NUM_ROWS = 3;
const int NUM_COLS = 30;
double forecast[NUM_ROWS][NUM_COLS];
double rainyDays = 0;
int rows, cols;
ifstream datafile;
datafile.open("RainOrShine.dat");
if (!datafile)
cout << "Error opening data file.\n";
else
{
cout << "Three-Month Analysis\n\n";
for(cols = 0; cols < NUM_COLS; cols++)
{
for(rows = 0; rows < NUM_ROWS; rows++)
{
}
}
}can someone please help me to go in the right direction? I really appreciate it
•
•
Join Date: Jan 2008
Posts: 3,836
Reputation:
Solved Threads: 503
•
•
•
•
I am supposed to be working on this problem that stores info in a 2x20 array of characters where the row indicates the month and the column indicates teh day. We have to read in from a file and then create a report that displays for each month and for the whole 2 month period..how many days were rainy, cloudy, and sunny. It also has to report which month had the largest num of rainy days...here's what i have so far:
#include <iostream> #include <fstream> using namespace std; int main() { const int NUM_ROWS = 3; const int NUM_COLS = 30; double forecast[NUM_ROWS][NUM_COLS]; double rainyDays = 0; int rows, cols; ifstream datafile; datafile.open("RainOrShine.dat"); if (!datafile) cout << "Error opening data file.\n"; else { cout << "Three-Month Analysis\n\n"; for(cols = 0; cols < NUM_COLS; cols++) { for(rows = 0; rows < NUM_ROWS; rows++) { } } }
can someone please help me to go in the right direction? I really appreciate it
{
cout << "Three-Month Analysis\n\n";
for(cols = 0; cols < NUM_COLS; cols++)
{
for(rows = 0; rows < NUM_ROWS; rows++)
{
// read in data?
}
}
}HOW to read in the data will depend on how the input file is set up.
•
•
Join Date: Apr 2009
Posts: 6
Reputation:
Solved Threads: 0
#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;
}
This is what I have so far....
#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;
}
This is what I have so far....
![]() |
Similar Threads
- Rain or Shine (C++)
- This or that? (Posting Games)
Other Threads in the C++ Forum
- Previous Thread: Noob Help Needed
- Next Thread: SpecialFolder::System
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines linker list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






