hey guys, I've seemingly exhausted all the possibilities within my limited knowledge, so I'm coming here for some assistance.
heres the problem:
Read the 20 students info into an array, assign the relevant grade, find the highest score, and print out all the names/scores in addition to the student/s of the highest score.
The student names should be outputted in this format:
Lazaar, John [grade]
And the student names must be left justified.
Thanks for even giving this a look, and thanks x1000000 for taking the time to help!!!
the plentiful errors are below the code, and are hopefully obvious stuff to you guys lol.
also one last thing, does anyone here with osx know what the file path would be if a file was on the desktop? This problem originally had to do with reading a file, but I spent hours on that thing and couldn't get my file read...
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct studentType
{
string studentFName;
string studentLName;
int testScore;
char grade;
}
void Data (studentType student[]);
void Grade (studentType student[]);
int high (studentType student[]);
void print(studentType student[],int highest);
int main()
{
studentType student [20];
Data(student[]);
void Grade (student[]);
int high (student[]);
void print(student[], int highest);
return 0;
void Data(studentType student[])
{
for (int x = 0; x < 20; x++)
{
cout << "Enter the student's Last Name: ";
cin >> student[x].studentLName;
cout << endl;
cout << "Enter the student's First Name: ";
cin >> student[x].studentFName;
cout << endl;
cout << "Enter the student's grade: ";
cin >> student[x].testScore;
cout << endl;
}
}
void Grade(studentType student[])
{
for (int x = 0; x < 20; x++)
{
if (student[x].testScore >= 90)
student[x].grade = 'A';
else if ( student[x].testScore >= 80 )
student[x].grade = 'B';
else if ( student[x].testScore >= 70 )
student[x].grade = 'C';
else if (student[x].testScore >= 60 )
student[x].grade = 'D';
else
student[x].grade = 'F';
}
}
int high (studentType student[])
{
int highest = student[0].testScore;
for (int x = 0; x < 20; x++)
{
if (student[x].testScore > highest)
highest = student[x].testScore;
}
return highest;
}
void printResult(student[], highest)
{
cout << setw(20) << "Student Name"
cout << setw(15) << "Score"
cout << setw(10) << "Grade" << endl;
for (int x = 0; x < 20; x++)
{
cout << left << student[x].studentLName << ", " <<
student[x].studentFName << endl;
}
cout << "The highest score is: " << highest << "." << endl;
cout << "The students with the highest scores are: " << endl;
for (int x = 0; x < 20; x++)
{
if (student[x].testScore == highest)
cout << left << student[x].studentLName << ", " << student[x].studentFName <<
endl;
}
}
aatest.cpp:17: error: new types may not be defined in a return type
aatest.cpp:17: note: (perhaps a semicolon is missing after the definition of 'studentType')
aatest.cpp:17: error: two or more data types in declaration of 'Data'
aatest.cpp: In function 'int main()':
aatest.cpp:26: error: expected primary-expression before ']' token
aatest.cpp:27: error: variable or field 'Grade' declared void
aatest.cpp:27: error: expected primary-expression before ']' token
aatest.cpp:28: error: expected primary-expression before ']' token
aatest.cpp:29: error: variable or field 'print' declared void
aatest.cpp:29: error: expected primary-expression before ']' token
aatest.cpp:29: error: expected primary-expression before 'int'
aatest.cpp:29: error: initializer expression list treated as compound expression
aatest.cpp:36: error: a function-definition is not allowed here before '{' token
aatest.cpp:54: error: a function-definition is not allowed here before '{' token
aatest.cpp:71: error: a function-definition is not allowed here before '{' token
aatest.cpp:84: error: variable or field 'printResult' declared void
aatest.cpp:84: error: expected primary-expression before ']' token
aatest.cpp:84: error: 'highest' was not declared in this scope
aatest.cpp:84: error: initializer expression list treated as compound expression
aatest.cpp:85: error: expected ',' or ';' before '{' token
aatest.cpp:106: error: expected `}' at end of input