Error 1 error C2447: '{' : missing function header (old-style formal list?)

I can't find the error:

Error 1 error C2447: '{' : missing function header (old-style formal list?)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  #include <iostream>
using namespace std;
double* PedirDatos (double* x,int num);
double CalcArea (double* x,double* y,int num);
void Imprimedatos (double* x,double* y, double area);

void main()
{
	int num;double area;
	cout<<"¿El área encerrada entre cuántos puntos quiere calcular?: ";
	cin>>num;
	system("cls");
	double *x = new double[num];
	double *y = new double[num];
	if (x == NULL) {cout<<"Error, no hay emoria"; exit(0);}
	if (y == NULL) {cout<<"Error, no hay emoria"; exit(0);}
	
	cout<<"Vamos a recoger las coordenadas X de sus "<<num<<" coordenadas:\n";
	x = PedirDatos ( x, num);//1A
	cout<<"Vamos a recoger las coordenadas Y de sus "<<num<<" coordenadas:\n";
	y = PedirDatos ( y,  num);//1B
	system("cls");
	area = CalcArea ( x, y, num);//2
	Imprimedatos (x, y, area);//3
	delete [] x; 
	delete [] y; 
}

//hacer el vector dinamico. (Los argumentos de entrada van a ser x e y
//por lo qu ese va a "invocar" dos veces a la función "PedirDatos"

double* PedirDatos (double* x,int* num);
{
	for (int i = 0 ; i<num ; i++) 
	{
		cout<<i+1<<") = ";
		cin<<x[i];
		cout<<endl;
		system("cls");
		return x;
	}
}
double CalcArea (double* x,double* y,int num);
{
	area += ((x[i]*y[i+1])-(y[i]*x[i+1]))/2;
	return area;
}
void Imprimedatos (double* x,double* y, double area);
{
	cout<<"\t *** CALCULO DE AREAS***\n\n";
	cout<<"AREA = "<<area<<"."<<endl;
	for (int j = 0 ; j<num ; j++) 
	{
		cout<<j<<"(X"<<j<<",Y"<<j<<") = "<<"( "<<x[j]<<" , "<<y[j]")";
	}
}
remove the semi colons n line 32 , 43, and 48.
line 21, your definition does not match the prototype.
1
2
double* PedirDatos (double* x,int num);
double* PedirDatos (double* x,int* num);


Line 45: i and area not defined.
Line 52: num not defined



I am very grateful, really, I think I just need a little help with line 37 of my new code, thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
using namespace std;
double* PedirDatos (double* x,int num);
double CalcArea (double* x,double* y,int num);
void Imprimedatos (double* x,double* y, double area,int num);

void main()
{
	int num;double area;
	cout<<"¿El área encerrada entre cuántos puntos quiere calcular?: ";
	cin>>num;
	system("cls");
	double *x = new double[num];
	double *y = new double[num];
	if (x == NULL) {cout<<"Error, no hay emoria"; exit(0);}
	if (y == NULL) {cout<<"Error, no hay emoria"; exit(0);}
	
	cout<<"Vamos a recoger las coordenadas X de sus "<<num<<" coordenadas:\n";
	x = PedirDatos ( x, num);//1A
	cout<<"Vamos a recoger las coordenadas Y de sus "<<num<<" coordenadas:\n";
	y = PedirDatos ( y,  num);//1B
	system("cls");
	area = CalcArea ( x, y, num);//2
	Imprimedatos (x, y, area,num);//3
	delete [] x; 
	delete [] y; 
}

//hacer el vector dinamico. (Los argumentos de entrada van a ser x e y
//por lo qu ese va a "invocar" dos veces a la función "PedirDatos"

double* PedirDatos (double* x,int num)
{
	for (int i = 0 ; i<num ; i++) 
	{
		cout<<i+1<<") = ";
		cin<<x[i];
		cout<<endl;
		system("cls");
		return x;
	}
}
double CalcArea (double* x,double* y,int num)
{
	double area; //¿¿this is correct??
	for (int ii = 0 ; ii<num ; ii++) 
	{
	area += ((x[ii]*y[ii+1])-(y[ii]*x[ii+1]))/2;
	}
	return area;
}
void Imprimedatos (double* x,double* y, double area,int num)
{
	cout<<"\t *** CALCULO DE AREAS***\n\n";
	cout<<"AREA = "<<area<<"."<<endl;
	for (int j = 0 ; j<num ; j++) 
	{
		cout<<j<<"(X"<<j<<",Y"<<j<<") = "<<"( "<<x[j]<<" , "<<y[j]<<")";
	}
}
Last edited on
What is wrong with line 37? We don't know what you are trying to do. Also you probably should change void main to int main. A main without a return is not the standard.
Line 37 cin<<x[i];

Change to cin>>x[i];

As a pneumonic aid, think of the angle brackets as pointing in the direction of data flow.

cin>>x[i] Information flows from the console into the variable x[i].

cout<<x[I] Information flows from the variable x[i] to the console for output.
[b][i]I've to give this for twomorrow and I can't complete, you have help me alot, really, but now the compilator sais that area is it not declared with a warning mesage

(What I want to do is asking the user some points and giving the area that is insi
de)


THE ERRORS NOW ARE THE FOLLOWING:

Warning 1 warning C4715: 'PedirDatos' : not all control paths return a value

Warning 2 warning C4700: uninitialized local variable 'area' used

I will not tire of thank [/i]you[/b]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

#include <iostream>
using namespace std;
double* PedirDatos (double* x,int num);
double CalcArea (double* x,double* y,int num);
void Imprimedatos (double* x,double* y, double area,int num);

void main()
{
	int num;double area;
	cout<<"¿El área encerrada entre cuántos puntos quiere calcular?: ";
	cin>>num;
	system("cls");
	double *x = new double[num];
	double *y = new double[num];
	if (x == NULL) {cout<<"Error, no hay emoria"; exit(0);}
	if (y == NULL) {cout<<"Error, no hay emoria"; exit(0);}
	
	cout<<"Vamos a recoger las coordenadas X de sus "<<num<<" coordenadas:\n";
	x = PedirDatos ( x, num);//1A
	cout<<"Vamos a recoger las coordenadas Y de sus "<<num<<" coordenadas:\n";
	y = PedirDatos ( y,  num);//1B
	system("cls");
	area = CalcArea ( x, y, num);//2
	Imprimedatos (x, y, area,num);//3
	delete [] x; 
	delete [] y; 
}

//hacer el vector dinamico. (Los argumentos de entrada van a ser x e y
//por lo qu ese va a "invocar" dos veces a la función "PedirDatos"

double* PedirDatos (double* x,int num)
{
	for (int i = 0 ; i<num ; i++) 
	{
		cout<<i+1<<") = ";
		cin<<x[i];
		cout<<endl;
		system("cls");
		return x;
	}
}
double CalcArea (double* x,double* y,int num)
{
	double area; //¿¿this is correct??
	for (int ii = 0 ; ii<num ; ii++) 
	{
	area += ((x[ii]*y[ii+1])-(y[ii]*x[ii+1]))/2;
	}
	return area;
}
void Imprimedatos (double* x,double* y, double area,int num)
{
	cout<<"\t *** CALCULO DE AREAS***\n\n";
	cout<<"AREA = "<<area<<"."<<endl;
	for (int j = 0 ; j<num ; j++) 
	{
		cout<<j<<"(X"<<j<<",Y"<<j<<") = "<<"( "<<x[j]<<" , "<<y[j]<<")";
	}
}
The first warning is probably if num is less than or equal to 0 then you will have no return statement.

As for the second warning line 46 area is undefined then you try and add to the undefined value on line 49. Try setting the initial value to 0 on line 46 then you can safely add to it.
33
34
35
36
37
38
39
40
41
42
43
double* PedirDatos (double* x,int num)
{
    for (int i = 0 ; i<num ; i++) 
    {
        cout<<i+1<<") = ";
        cin<<x[i];
        cout<<endl;
        system("cls");
        return x;
    }
}

The return x; here should probably be outside of the loop.
@giblit is right plus this point :
In function PedirDatos you seem to be filling an array named x ;
You used a for loop which is correct , BUT every time in this 'for' loop you seem to be returning the 'x' .
SO it runs the loop for the first time and returns X , SO it exits the function .
I think what you need to do is to move that "return x ;" statement out of your for loop ;


Plus that in your last code in line 38 you still have this : "<<" instead of ">>"
Thank you all, really, for your help I 've been able to find all the problems of the program, and I leave it here in case in the future can serve someone

thank you very much, try it WORKS!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73



#include <iostream>
using namespace std;
double* PedirDatos (double* x,int num);
double CalcArea (double* x,double* y,int num);
void Imprimedatos (double* x,double* y, double area,int num);

void main()
{
	int num;
	double area;
	cout<<"¿El área encerrada entre cuántos puntos quiere calcular?: ";
	cin>>num;
	if (num <= 0){exit(0);}
	system("cls");
	double *x = new double[num];
	double *y = new double[num];
	if (x == NULL) {cout<<"Error, no hay emoria"; exit(0);}
	if (y == NULL) {cout<<"Error, no hay emoria"; exit(0);}
	
	cout<<"Vamos a recoger las coordenadas X de sus "<<num<<" coordenadas:\n";
	x = PedirDatos ( x, num);//1A
	cout<<"Vamos a recoger las coordenadas Y de sus "<<num<<" coordenadas:\n";
	y = PedirDatos ( y,  num);//1B
	system("cls");
	area = CalcArea ( x, y, num);//2
	Imprimedatos (x, y, area,num);//3
	delete [] x; 
	delete [] y; 
}

//hacer el vector dinamico. (Los argumentos de entrada van a ser x e y
//por lo qu ese va a "invocar" dos veces a la función "PedirDatos"

double* PedirDatos (double* x,int num)
{
	for (int i = 0 ; i<=num-1 ; i++) 
	{
		cout<<i+1<<") = ";
		cin>>x[i];
		cout<<endl;
		system("cls");	
	}
	return x;
}
double CalcArea (double* x,double* y,int num)
{
	double area = 0;
	double estacionario = 0;
	for (int ii = 0 ; ii<=num-2 ; ii++) 
	{

	estacionario = ((x[ii]*y[ii+1])-(y[ii]*x[ii+1]));
	if (estacionario<0){area =area + estacionario * (-1);}else{area = area + estacionario;}
	}
	area = area / 2;
	return area;
}
void Imprimedatos (double* x,double* y, double area,int num)
{
	cout<<"\t *** CALCULO DE AREAS***\n\n";
	cout<<"AREA = "<<area<<"."<<endl;
	for (int j = 0 ; j<num ; j++) 
	{
		cout<<j<<"(X"<<j<<",Y"<<j<<") = "<<"( "<<x[j]<<" , "<<y[j]<<")";
		cout<<endl;
	}
}


Topic archived. No new replies allowed.