The output portion of the do/while loop below (i.e. MENU) outputs twice once youve selected your choice, and I have no idea why its doing this.
#include<iostream>
using namespace std;
struct StudentRecord
{ int stuId;
char name[20];
char grade[4];
};
void showOneRecord(StudentRecord);//display a student record
void showRecords(StudentRecord[],int);//display all student records
void bubbleSort(StudentRecord[],int);//sort student records by student id in ascending order
int binarySearch(StudentRecord[],int,int);//search a student record by binary search
int sequentialSearch(StudentRecord[],int,int);//search a student record by sequential search
int main()
{ int const SIZE=6;
StudentRecord stu[SIZE]={{231,"Avalrez, Luis","B\n"},{567,"Dreian, Arlen","C\n"},{145,"Tol, Norith","A\n"},{786,"Garcia, Steven","D\n"},{362,"Arenas, Jennifer","B\n"},{421,"Solis, Ernesto","A\n"}};
char choice;//stores only one character
do
{ cout<<"---------------MENU---------------"<<endl;
cout<<"a. Search student by sequential search."<<endl;
cout<<"b. Search student by biary search."<<endl;
cout<<"c. Display student records."<<endl;
cout<<"d. Exit."<<endl;
cout<<"Enter your choice (a, b, c or d): ";
choice=cin.get();
switch(choice)
{ case'a':
cout<<"\nEnter student ID number: "<<endl;
cout<<"\nStudent information: "<<endl;
break;
case'b':
cout<<"\nEnter student ID number: "<<endl;
cout<<"\nStudent information: "<<endl;
break;
case'c':
cout<<"\nStudent Records:\n"<<endl;
showRecords(stu,SIZE);
break;
}
}while(choice!='d');
system ("PAUSE");
return 0;
}
void showRecords(StudentRecord stu[], int SIZE)
{ for(int i=0;i<SIZE;i++)
{ cout<<stu[i].stuId<<endl;
cout<<stu[i].name<<endl;
cout<<stu[i].grade<<endl;
}
}