这里是我的代码,我的语句是while循环开始运行显示选项,并在第一次迭代但在第二次迭代选择扫描选择时不会被再次分配和以前的选择被记住。 问题是什么 ? (我使用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 */