I can't figure out why my case 4 won't work. Every case is suppose to cls after the operation finish. But somehow case 4 will just ignore and go back to main menu.
string firstName[num_student];
string lastName[num_student];
unsigned int studentId[num_student]={0};
char option;
char answer;
int temp;
int size = sizeof(studentId)/sizeof(unsigned int);
do
{
system("cls");
cout<<endl<<endl;
cout<<setw(46)<<"1. Create a student list"<<endl<<endl;
cout<<setw(54)<<"2. Search a student by studentId"<<endl<<endl;
cout<<setw(59)<<"3. Sort the student list by studentId"<<endl<<endl;
cout<<setw(49)<<"4. Display the student list"<<endl<<endl;
cout<<setw(41)<<"5. Quit the program"<<endl<<endl;
cout<<endl<<setw(44)<<"Enter your choice: ";
cin>>option;
system("cls");
switch (option)
{
case '1' :
{
for(int index=0;index<num_student;index++)
{
cout<<endl<<endl<<"Enter student ID : ";
cin>>studentId[index];
cin.ignore();
cout<<endl<<"Enter first name : ";
getline(cin,firstName[index]);
cout<<endl<<"Enter last name : ";
getline(cin,lastName[index]);
}
}
break;
case '2' :
{
int searchId;
bool found=false;
cout<<endl<<endl<<"\tEnter student ID : ";
cin>>searchId;
for (int a=0;a<num_student;a++)
{
if(searchId==studentId[a])
{
cout<<endl<<"\tStudent ID : "<<studentId[a];
cout<<endl<<endl<<"\tStudent first name : "<<firstName[a];
cout<<endl<<endl<<"\tStudent last name : "<<lastName[a];
found=true;
}
}
if(!found)
{
cout<<endl<<endl<<"\tThis student ID doesn't exist.";
cout<<endl<<endl<<"\tTry again? (Y or N) : ";
cin>>answer;
case'4' :
for(int i=0;i<num_student;i++)
{
cout<<endl<<"\tStudentID : "<<studentId[i];
cout<<endl<<"\tFirst name : "<<firstName[i];
cout<<endl<<"\tLast name : "<<lastName[i];
cout<<endl;
}
break;
from what I saw, you don't have any clear screens in any of the cases.
there are system("cls"); in the do loop before the cases only.
you have extra braces after some case statements.