problem functions and structure

i have always error does not appear and i dont know what is the way to avoid

this is it

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

its in line 4

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
# include <iostream>
# include <string>
using namespace std;

	struct studenttype
	{
		string name;
		long ID;
		float testscore;
	};
	void Readallmembers(studenttype list[])
	{
		for(int i=0 ; i<5 ; i++)
		cout <<"Enter Name ID and test score: ";
		cin >> list.name >> list.ID >> list.testScore;
	}
	void Print(studenttype list[])
	{
		int loc=0;
		for(int i=1 ; i<5 ; i++)
		if(list[i].testscore < list[loc].testscore)
		loc=i;
		cout << list[loc].name << list[loc].ID << list[loc].testscore;
	}
		
		int main()
		{
			studenttype ITCS104student[5];
            Readallmembers(ITCS104student[i]);
			print(ITCS104student[i]);
			return 0;
		}

		




its in line 4

what is the wrong i did

and what is the correction for that
Last edited on
using namespace std; is a global declaration, it's not a function header.

Simply delete line 4 and line 34,

Second, cout << list[loc].name << list[loc].ID << list[loc].testscore; is outside of a function so it'll never be called (it'll also never be compiled).
... ¿why did you open a brace there?
when i delete line 4 and line 34 it show me more errors what i have to do ?
When you deleted line 4 and 34, you actually just uncovered the errors that were already there.

Deal with them one at a time starting from the first one.

When I compile this without lines 4 and 34 I get:
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
# include <iostream>
# include <string>
using namespace std;

struct studenttype
{
	string name;
	long ID;
	float testscore;
};
void Readallmembers(studenttype list[])
{
	cout <<"Enter Name ID and test score: ";
	cin >> arr.name >> arr.ID >> arr.testScore;
}
void Print(studenttype list[])
{
	loc=0;
	for(int i=1 ; i<5 ; i++)
		if(list[i].testscore < list[loc].testscore)
			loc=i;
}
cout << list[loc].name << list[loc].ID << list[loc].testscore;
int main()
{
	studenttype ITCS104[5];
	for(int i=0 ; i<5 ; i++)
		Readallmembers(ITCS104student[i]);
	print(ITCS104student[i]);
	return 0;
}
1>Snippets.cpp(14): error C2065: 'arr' : undeclared identifier
1>Snippets.cpp(14): error C2228: left of '.name' must have class/struct/union
1>          type is ''unknown-type''
1>Snippets.cpp(14): error C2065: 'arr' : undeclared identifier
1>Snippets.cpp(14): error C2228: left of '.ID' must have class/struct/union
1>          type is ''unknown-type''
1>Snippets.cpp(14): error C2065: 'arr' : undeclared identifier
1>Snippets.cpp(14): error C2228: left of '.testScore' must have class/struct/union
1>          type is ''unknown-type''
1>Snippets.cpp(18): error C2065: 'loc' : undeclared identifier
1>Snippets.cpp(20): error C2065: 'loc' : undeclared identifier
1>Snippets.cpp(20): error C2228: left of '.testscore' must have class/struct/union
1>Snippets.cpp(21): error C2065: 'loc' : undeclared identifier
1>Snippets.cpp(23): error C2143: syntax error : missing ';' before '<<'
1>Snippets.cpp(23): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>Snippets.cpp(28): error C2065: 'ITCS104student' : undeclared identifier
1>Snippets.cpp(29): error C2065: 'ITCS104student' : undeclared identifier
1>Snippets.cpp(29): error C2065: 'i' : undeclared identifier
1>Snippets.cpp(29): error C3861: 'print': identifier not found


First, error C2065: 'arr' : undeclared identifier, you haven't defined arr yet. I think you meant to do this as the argument to the function. Change line 11:
void Readallmembers(studenttype list[])
to
void Readallmembers(studenttype& arr)

If I fix all of the compilation errors I get:
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
# include <iostream>
# include <string>
using namespace std;
// { removed because it's wrong

struct studenttype
{
	string name;
	long ID;
	float testscore;
};
void Readallmembers(studenttype& arr) // corrected the name arr and we now pass-by-reference
{
	cout <<"Enter Name ID and test score: ";
	cin >> arr.name >> arr.ID >> arr.testscore; // testScore vs testscore... case sensitive!
}
void Print(studenttype list[])
{
	int loc=0; // missing int type
	for(int i=1 ; i<5 ; i++)
		if(list[i].testscore < list[loc].testscore)
			loc=i;
	cout << list[loc].name << list[loc].ID << list[loc].testscore;
} // This was moved down a line, cout << anything needs to be in a function
int main()
{
	studenttype ITCS104[5];
	for(int i=0 ; i<5 ; i++)
		Readallmembers(ITCS104[i]); // You hand't declared ITCS104student
	Print(ITCS104); // Print is case sensitive, You don't need to pass [i] when recieving an array
	return 0;
}

// } removed because it's wrong 
Last edited on
thank you for correcting my bad mistakes
Topic archived. No new replies allowed.