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).
# include <iostream>
# include <string>
usingnamespace 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)
# include <iostream>
# include <string>
usingnamespace 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