Hello.
I made a program like this:
Code:
#include <stdio.h>
typedef struct student {
char name[20];
int id;
int grade;
} student;
int main() {
student p;
while (1) {
printf("type a name: ");
gets_s(p.name, 19);
if (*p.name == 'q') break;
printf("type the id: ");
scanf_s("%d", &p.id, sizeof(int));
printf("type the grade: ");
scanf_s("%d", &p.grade, sizeof(int));
switch (p.grade / 5) {
case 20:
case 19: printf("A+\n"); break;
case 18: printf("A\n"); break;
case 17: printf("B+\n"); break;
case 16: printf("B\n"); break;
case 15: printf("C+\n"); break;
case 14: printf("C\n"); break;
case 13: printf("D+\n"); break;
case 12: printf("D\n"); break;
default: printf("F\n");
}
}
return 0;
}
I expect the program continues to get "new person" in each cycle, but the result looks like this:
type a name: iam
type the id: 1994
type the grade: 97
A+
type a name: type the id: myname
type the grade: A+
type a name: type the id: hello
type the grade: A+
type a name: type the id: what's going on?
type the grade: A+
type a name: type the id:
Would you plz explain what the problem is?