I'm having a problem with my program. This program will display the numbers and get the average of them, average of positive and negative numbers, and also display the largest element.
I have 3 files. For header, other functions and main function.
Prog.h
#ifndef Prog
#define Prog
class Prog
{
public:
void ReadList(int Array[], int N);
void Avgs (int Array[], int N, int &Ave, int &aveP, int &AveN);
int Large (int Array[], int N);
void Display(int Array[], int N, int Ave, int AveP, int AveN, int Max);
private:
int N;
int Array[10];
}
#endif
Prog.cpp
#include <iostream>
#include <fstream>
#include "Prog.h"
using namespace std;
void ReadList(int Array[], int N)
{
ifstream fin;
fin.open ("file1.dat");
for(N=0; N<10; N++)
fin >> Array[N];
fin.close();
ofstream fout;
fout.open("file2.dat");
fout << Array[N];
fout.close();
cout << Array[N];
}
void Avgs (int Array[], int N, int &Ave, int &AveP, int &AveN)
{
int sum=0;
for(N=0; N<10; N++)
{
sum = sum + Array[N];
}
Ave= sum/10;
int N2, N3;
int pos[10], nega[10], temp;
int sum_P=0, sum_N=0;
for(N=0; N<10; N++)
{
if (Array[N]>0)
{
pos[N2]=Array[N];
sum_P= sum_P + pos[N2];
N2++;
}
else if (Array[N]<0)
{
nega[N3]=Array[N];
sum_N= sum_N + nega[N3];
N3++;
}
else
{
temp++;
}
}
AveP= sum_P/N2;
AveN= sum_N/N3;
cout << " " << Ave << " " << AveP << " " << AveN;
return;
}
int Large (int Array[], int N)
{
int Max=0;
for(N=0; N<10; N++)
{
if(Array[N]>Max)
{
Max=Array[N];
}
}
cout << " " << Max;
return Max;
}
void Display(int Array[ ], int N, int Ave, int AveP, int AveN, int Max)
{
int a, b;
ReadList(Array[], N);
Avgs (Array[], b, Ave, AveP, AveN);
Large (Array[], N);
return;
}
Main.cpp
#include <iostream>
#include "Prog.h"
using namespace std;
int main()
{
int c, d, e, f;
cout << Display(Array[], N, c, d, e, f);
return 0;
}
I'm having a problem with:
using namespace std;
\prog.cpp(6): warning C4094: untagged 'class' declared no symbols
\prog.cpp(6): error C2143: syntax error : missing ';' before 'using'
And also in my main.cpp...
ReadList(Array[], N);
Avgs (Array[], b, Ave, AveP, AveN);
Large (Array[], N);
\prog.cpp(84): error C2059: syntax error : ']'
\prog.cpp(85): error C2059: syntax error : ']'
\prog.cpp(86): error C2059: syntax error : ']'
int main()
{
int c, d, e, f;
cout << Display(Array[], N, c, d, e, f);
return 0;
}
\main.cpp(11): error C2065: 'Array' : undeclared identifier
\main.cpp(11): error C2059: syntax error : ']'
\main.cpp(11): error C3861: 'Display': identifier not found
i don't know how should i take this error... thank you