I'm writing a class planner, where the user is given the opportunity to enter certain information about their classes and have it printed back to them upon request.
The problem I'm having is that whenever I enter any text into the input with a space in it, it returns me to menu().
I also tried using string in my structured array, but then it simply skipped the entire input for that variable.
I'm using a struct in my header file to allow simple input into the array:
struct Classes
{
char ClassName[30];
int ClassNumber;
char DaysMet[20];
int StartTime;
int EndTime;
char Teacher[20];
int Students;
};
and here is the input form:
int Input()
{
system("cls");
if (currentindex > IndexNum)
cout << "Index is full" << endl;
else while (currentindex < IndexNum)
{ cout << "Class Name: ";
cin >> Course[currentindex].ClassName;
cout << "Class Number: ";
cin >> Course[currentindex].ClassNumber;
cout << "Days Met: ";
cin >> Course[currentindex].DaysMet;
cout << "Start Time: ";
cin >> Course[currentindex].StartTime;
cout << "End Time: ";
cin >> Course[currentindex].EndTime;
cout << "Teacher: ";
cin >> Course[currentindex].Teacher;
cout << "Students: ";
cin >> Course[currentindex].Students;
currentindex++;
}
Menu();
return 0;
}
Another way I attempted to get the program to accept input into my char 'ClassName'
cin.getline(Course[currentindex].ClassName, 30)
So, basically anyone who uses this program cannot enter data into the program when the variable has more than one word, for example:
Class Name: "Civics and Economics"
or
Teacher: "Mr. Mathus"
would send the user back to the main menu!
I'm totally clueless as to how to resolve this problem, thanks in advance!