Special Prize to whoever finds the errors
Challenge problem: Where are the two errors???
Code:
//Homework 18.4
//Benjamin Stollerman
//CS 1050
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
using namespace std;
int main()
{
//Define and initialize variables and 2D array
double lake[5][12];
double num_years[5];
double average[5];
double num=0;
//Attach object name
fstream powell_data;
// Associate object name to a file
powell_data.open("lake_powell.dat",ios::in);
/*Part A- Calculate the average elevation of the water level for each year
and for 5 year period*/
for(int k=0; k<12; k++)
//for loop
{
for(int j=0; j<5; j++)
powell_data>>lake_data[j][k];
//read in the data from above
}
for(int k=0; k<5;k++)
{
num_years[k] = 0;
for(int j=0; j<12; j++)
num_years[k] = lake[k][j]+1;
num += num_years[k];
}
for(int k=0; k<5; k++)
{
average[k]=0;
for(int j=0; j<12; j++)
{
if(lake[k][j] > (num_years[k]/12))
average[k] = average[k]+1;
}
cout<<"In "<<k+2000<<"The average elevation was: "<<(num_years[k]/12)<<endl;
cout<<"There were "<<average[k]<<" months above average"<<endl;
}
cout<<"The 5-year average elevation was: "<<(total/60)<<endl;
return 0;
}
Thankee very much!