该程序的目标是使用函数创建一个输入学生ID及其考试成绩的表。然后将测试成绩转换为字母成绩。我的问题是程序输出内存而不是输入的数字。我知道我在某个地方犯了错误,但我似乎想不出来。非常感谢您的帮助。
#include <stdio.h>
#define NUM 12
void obtain_id_scores (int [], int []);
void get_letter_grade (char [], int []);
void display_results (int [], int [], char []);
int main (void)
{
int student_id [50];
int test_score [50];
char letter_grade [50];
obtain_id_scores (student_id, test_score);
get_letter_grade (letter_grade, test_score);
display_results (student_id, test_score, letter_grade);
return 0;
} /* End Main. */
void obtain_id_scores (int student_id [], int test_score [])
{
int x;
for (x = 1; x <= NUM; ++x)
{
printf (" Enter student ID and test grade: ");
scanf ("%s %s", &student_id [x], &test_score [x]);
fflush (stdin);
}
}
void get_letter_grade (char letter_grade [], int test_score [])
{
int x;
for (x = 1; x <= NUM; ++x)
{
if (test_score [x] > 100)
letter_grade [x] = 'N';
else if (test_score [x] >= 90)
letter_grade [x] = 'A';
else if (test_score [x] >= 80)
letter_grade [x] = 'B';
else if (test_score [x] >= 70)
letter_grade [x] = 'C';
else if (test_score [x] >= 60)
letter_grade [x] = 'D';
else
letter_grade [x] = 'F';
}
}
void display_results (int student_id [], int test_score [], char letter_grade [])
{
int x;
/* Display Results */
printf (" Student Grade Report\n");
printf (" ---------------------\n\n");
printf (" ID TEST SCORE LETTER GRADE\n");
/* Display all IDs, test scores, and letter grades. */
for (x = 1; x < NUM; ++x)
{
printf ("%6i %6i %8c\n", student_id[x], test_score[x], letter_grade[x]);
}
}