I am trying to display the student information for a search but it's not working for the names. The string nameArray[1][5] has the first and last name as a single element so when I search string name, I'm searching for the full name. Right now, I can only find the first element of the array and when I type another name to search for, it says it cannot be found. I think this has to do with the fact that there are spaces in some of the strings that I do not know about or something. Any ideas to help?
//S. Search by student name to display all scores for a particular student
case'S' :
case's' :
cout << "Enter student's first name: ";
//prompt user for a search value
cin.ignore();
getline(cin, name);
//check if the name is on the list
for (int i = 0; i < SIZE; i++) {
if (nameArray[i] == name){
found = true;
student = i;
break;
}
}
if (found)
{
cout << setw(20) << left << "Name" << setw(25) << left << "Scores"
<< setw(5) << left << "Grade" << endl
<< "---------------------------------------------------" << endl;
cout << setw(22) << left << nameArray[student];
for (int j = 0; j < col; j++)
{
cout << scoreArray[student][j] << " ";
}
cout << setw(10) << right << gradeArray[student] << " " << letterArray[student];
}
else cout << "No record found." << endl;
break;
Along with what Repeater said there is so much in that bit of code that is not shown. We have no idea what these arrays are, how they are defined or how they are loaded.
When you load the array does it come from a file, a sample of this file would help, or user input and what do you expect the user to input.
The variable "student". Where did that come from, what value should it have and how does it change? From what I see only one row of the array will be checked.
Right now with that little bit of code it is hard to say if it is right or wrong without the rest of the program.
Personally I like a complete program that I can run and test. Sometimes running a program is the best way to understand what is happening. And if there is a file used for input by the program that is helpful. If the file is large a small sample of 4 or 5 records will do.
This will help to keep the questions down about what something is, what value is in a variable and what value is expected in that variable.