can you please explain to me why htese errors happen and what is the solutions for this...pleeeaaassee..:))

Problem:
Write a C++ program which will read in a list of numbers, find the average of all numbers, the average of thepositive and negative numbers, and the largest element. Your program should contain at least four functions --one to read in the list, one to write it out, one to get the averages, and one to find the largest element.
Use the following test data (there are two sets):
A) 4 -30 0 7 42 -20 18 400 -123 -6

#include<iostream>
#include<fstream>
using namespace std;

void Avgs(int Array[],int N,int& Ave,int& AveP,int& AveN){
AveP = 0;
AveN =0;

for(N=0,N<10,N++;;)
	Ave=Ave+ Array[N];
Ave=Ave/10;

for(N=0,N<10,N++;;){
	if (Array[N]>= 0)
		AveP= AveP+Array[N];
		else
		AveN= AveN+Array[N];
}
AveP= AveP/6;
AveN= AveN/4;
}
int Large(int Array[],int N, int& Big);{
 int Big = 0
for(N=0,N<10,N++;){
	if (Array[N] > Big)
		Big= Array[N]}
return Big
}
void Display(int Array[],int N, int AveP,int AveN,int Max){
for(N=0,N<10,N++;;)
int Big = Max;
cout<<Array[N]<<endl;
cout<<"The Average of the Positive Numbers is:"<<AveP<<endl;
cout<<"The Average of the Negative Numbers is:"<<AveN<<endl;
cout <<"The Biggest Integer is:"<<Max<<endl;
}


void Readlist(int Array[],int N){
ifstream fin;
fin.open("Input.txt");


	for(N=0,N<10,N++;;)
	fin>>Array[N];
	fin. close();

}
int main() {
int A,B,C,D,E,F,G,H,I,J,K,Array[10];

Readlist(Array[10],A);
	 Avgs(Array[10],B,C,D,E);
     Large(Array[10],F,G);
	 Display(Array[10],H,I,J,K);
return 0;
}

Recommended Answers

All 2 Replies

this is the errors....


D:\12-22-10\jhyjhjkh.cpp(22) : error C2447: missing function header (old-style formal list?)
D:\12-22-10\jhyjhjkh.cpp(52) : error C2664: 'Readlist' : cannot convert parameter 1 from 'int' to 'int []'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
D:\12-22-10\jhyjhjkh.cpp(53) : error C2664: 'Avgs' : cannot convert parameter 1 from 'int' to 'int []'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
D:\12-22-10\jhyjhjkh.cpp(54) : error C2664: 'Large' : cannot convert parameter 1 from 'int' to 'int []'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
D:\12-22-10\jhyjhjkh.cpp(55) : error C2664: 'Display' : cannot convert parameter 1 from 'int' to 'int []'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.

When troubleshooting, you should always address the first reported error first. The first error says

D:\12-22-10\jhyjhjkh.cpp(22) : error C2447: missing function header (old-style formal list?)

This error refers to the header line of this function:

int Large(int Array[],int N, int& Big);{
  int Big = 0
  for(N=0,N<10,N++;){
    if (Array[N] > Big)
    Big= Array[N]}
  return Big }

Your header has a semi-colon in it that it shouldn't. The semi-colon makes it a prototype instead of a header. Also, I see several other missing and incorrect semi-colons within this function.

The next 4 errors refer to these lines:

/*52*/ Readlist(Array[10],A);
/*53*/ Avgs(Array[10],B,C,D,E);
/*54*/ Large(Array[10],F,G);
/*55*/ Display(Array[10],H,I,J,K);

When you are passing an array to a function, you only use the array's name, you don't use an index. When you use an index, you are attempting to send that specific element of the array instead of the actual array. This is a better way to do it:

//prototype
void ReadList (int *, int);

//call
ReadList (arrayName, arraySize);

//definition
void ReadList (int *theArray, int arraySize) {
  //function implementation
  for (int i = 0; i < arraySize; ++i) {
    cin >> theArray[i];
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.