我在几个不同的论坛上尝试过,似乎无法得到一个直接的答案,我怎样才能让这个函数返回结构?如果我尝试'return newStudent;' 我收到错误“不存在从 studentType 到 studentType 的合适的用户定义转换。”
// Input function
studentType newStudent()
{
struct studentType
{
string studentID;
string firstName;
string lastName;
string subjectName;
string courseGrade;
int arrayMarks[4];
double avgMarks;
} newStudent;
cout << "\nPlease enter student information:\n";
cout << "\nFirst Name: ";
cin >> newStudent.firstName;
cout << "\nLast Name: ";
cin >> newStudent.lastName;
cout << "\nStudent ID: ";
cin >> newStudent.studentID;
cout << "\nSubject Name: ";
cin >> newStudent.subjectName;
for (int i = 0; i < NO_OF_TEST; i++)
{ cout << "\nTest " << i+1 << " mark: ";
cin >> newStudent.arrayMarks[i];
}
newStudent.avgMarks = calculate_avg(newStudent.arrayMarks,NO_OF_TEST );
newStudent.courseGrade = calculate_grade (newStudent.avgMarks);
}