|
-
April 18th, 2010, 10:46 PM
#1
Function Call Problem.
Like the title says, I need to reformat my code so it calls the functions. Here is the original code so you can have something to relate too. I've tried doing it myself, but the most common error I get is that I cannot change float[4][12] to float[][1] when I made an averageJuly function. So can anyone rearrange it for me, so I can see what it should look it. I've been relating it to past projects and it seems I'm still doing something wrong. A visual of code will help. Thanks.
Code:
#include<iostream>
#include<conio.h>
#include<fstream>
#include<iomanip>
using namespace std;
const int row=4;
const int column=12;
void main()
{
ifstream infile;
float table[row][column];
int month, year;
float total=0, total2=0, totalJuly=0, total_6months=0;
infile.open("data.txt");
for(year=0; year<row; year++)
{
for(month=0; month<column; month++)
{
infile>>table[year][month];
cout<<setw(3)<<year<<setw(3)<<month<<setw(8)<<table[year][month]<<endl;
}
cout<<endl;
}
for(year=0; year<4; year++)
totalJuly+=table[year][6];
cout<<"Average for July over 4 years is "<<setprecision(4)<<totalJuly/4<<endl;
for (month=0; month<6; month++)
total_6months+=table[0][month];
cout<<"Average for the first 6 months is "<<setprecision(4)<<total_6months/6<<endl;
for(month=0; month<column; month++)
total+=table[0][month];
for(month=0; month<column; month++)
total2+=table[3][month];
cout<<"Average price for first and last year is "<<setprecision(4)<<(total+total2)/24<<endl;
infile.close();
getch();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|