In my random group sorter project, I am receiving an error that I am not sure how to resolve on my own. The code block I'm focusing on for this error:
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <time.h>
using namespace std;
class student
{
public:
string nameFirst;
string nameLast;
string nameFull;
};
student typeName()
{
student bar;
cout << "Type in a student's first name: ";
cin >> bar.nameFirst;
cout << "Type in that student's last name: ";
cin >> bar.nameLast;
cout << "\n";
bar.nameFull = bar.nameFirst + " " + bar.nameLast;
return bar;
}
void options()
{
cout << "Select what you want to do:\n";
cout << "1) Exit application\n";
cout << "2) Enter a Student\n";
cout << "3) Display Students\n";
cout << "4) Display Groups\n";
cout << "5) Output groups as text file\n";
cout << "\n";
}
int main()
{
student allStudents[50]; // Having 50 students alone is ridiculous
bool endProg = 0;
int maxStudents;
int studentsPerGroup;
int optionSelect;
int studentHeadCount = 0;
cout << "GroupPicker 1.0\n";
cout << "How many students are in the class? (Note: You cannot have more than 50 in this program)\n";
cin >> maxStudents;
if (maxStudents > 50)
{
cout << "Too many students! Exiting program...\n";
system("PAUSE");
exit(1);
}
cout << "How many students per group?\n";
cin >> studentsPerGroup;
while (endProg == 0) {
options();
cin >> optionSelect;
switch (optionSelect) {
case 1:
endProg = 1;
break;
case 2:
allStudents[maxStudents] = typeName();
studentHeadCount++;
break;
case 3:
cout << "Current list of students:\n";
for (int i = 0; i < studentHeadCount; i++)
{
cout << allStudents[i] << endl; // error points to here
}
break;
case 4: // Still coding this section
if (studentHeadCount < studentsPerGroup)
{
cout << "Invalid group parameters. Returning to main menu...\n";
break;
}
else
{
cout << "Here are the groups:\n";
}
case 5: // Still coding this section
cout << "Saving groups to file...";
}
}
}
In the event that 3 is the menu input, the program should display the current list of students entered into allStudents[i]
until the i
matches the value of studentHeadCount
. However, I am receiving an error C2679, because it claims that I'm using an invalid operator. Did I write something wrong?