Here is my code, my statements is that when while loop starts to run show options and scan the selection at first iteration but in second iteration choice is not assigned again and previous selection is remembered. What is the problem ? (I am using VS2012)
while (!done){
int choice;
printf("\n------- STUDENT INFORMATION SYSTEM MAIN MENU --------\n");
printf("1-Load students from the database\n");
printf("2-Print existing students on the screen\n");
printf("3-Add a new student\n");
printf("4-Delete an existing student\n");
printf("5-Find an existing student\n");
printf("6-Quit\n");
printf("====> Choice? ");
scanf("%d", &choice);
switch(choice){
case 1:
LoadStudentsFromDatabase();
printf("Students loaded from database successfully\n");
break;
case 2:
PrintExistingStudentsOnTheScreen();
break;
case 3:
printf("\nFirstName: "); scanf("%s", s.firstName);
printf("LastName: "); scanf("%s", s.lastName);
printf("ID: "); scanf("%d", &s.id);
printf("Gpa: "); scanf("%f", &s.gpa);
printf("Department: "); scanf("%d", &s.department);
AddStudent(&s);
printf("1 student added\n");
break;
case 4:
printf("\nID? "); scanf("%d", &id);
if (DeleteStudent(id)){
printf("Student deleted successfully\n");
} else {
printf("Failed to delete the student. Does not exist?\n");
} /* end-else */
break;
case 5:
printf("\nID? "); scanf("%d", &id);
ps = FindStudent(id);
if (ps == NULL){
printf("Student not found\n");
} else {
char *depts[] = {"CS", "EE", "IE", "CE", "ME"};
printf("+--------------------+--------------------+------+------+------+\n");
printf("| FirstName | LastName | ID | GPA | Dept |\n");
printf("+--------------------+--------------------+------+------+------+\n");
printf("|%20s|%20s|%6d|%6.2f|%6s|\n", ps->firstName, ps->lastName, ps->id, ps->gpa, depts[ps->department]);
printf("+--------------------+--------------------+------+------+------+\n");
} //end-else
break;
case 6:
done = 1;
break;
default:
printf("!!!!!!!!!! Invalid choice. Try again :-))\n");
break;
} /* end-switch */
} /* end-while */