Here is the code:
void option5 (StudentRecord student[], int n)
{
double gpaThreshold;
char enteredMajor;
int i;
cout << "Enter a GPA threshold: ";
cin >> gpaThreshold;
cin.ignore(80, '\n');
cout << "Enter a Major: ";
cin >> enteredMajor;
cin.ignore(80, '\n');
enteredMajor = toupper(enteredMajor);
for (i = 0; i < n; i++)
{
if (student[i].gpa >= gpaThreshold && student[i].major == enteredMajor)
{
if (i % 10 == 0)
{
cin.ignore();
}
cout << setw(3) << right << i+1 << ". "
<< setw(20) << left << student[i].lastName
<< setw(20) << left << student[i].firstName
<< setw(8) << left << student[i].major
<< fixed << setprecision(2) << setw(8) << left << student[i].earnedHours
<< fixed << setprecision(2) << setw(6) << left << student[i].gpa << endl;
}
}
}
StudentRecord is a struct, and the only integer on that line is ‘i’, whereas the pointer (I would have to assume) is .major.
I’m wanting to compare an entered major, with the “Major” values in the array.
E.G. I type in Chem
-turns to CHEM
-fetches all students under that major (and threshold of GPA)
-displays the above statement (all students of ‘X’ major)
Any suggestions? Help? Comments? Positive/Negative Feedback?
EDIT: Here is the struct:
struct StudentRecord
{
char lastName [16]; // field definitions of the structure
char firstName[16];
char hometown [16];
char major[5];
int studentNumber;
double balance;
int earnedHours;
double gpa;
};
Consider this fragment:
student[i].majoris achar[5], which devolves into achar*in this context. This is a pointer type.enteredMajoris achar. This is an integral type.You cannot compare these types.
Perhaps you meant to decalre
enteredMajorthus:and compare them like this: