C语言字符数组的问题

来源:百度知道 编辑:UC知道 时间:2024/05/13 03:37:19
(2)编写程序
①记录并统计一个班级学生的成绩,其中每位学生有三门课分别是VFP、C program、VB,要求从键盘输入班级人数并输入每位学生的学号、姓名、及三门课的成绩,输出学生的学号三门课成绩、平均分以及每门课的平均分。
②口令检查。提示用户输入一个口令。 用户输入口令后,程序对其进行检查:口令对,则提示:“yes”。口令不对,则提示:“password error”且用户的口令输入不得超过3次。若超过3次,则提示“password error, please exit”。
用字符数组做,我刚学,不太会,哪位高手帮帮忙!!!!

/*
*①记录并统计一个班级学生的成绩,其中每位学生有三门课分别是
*VFP、C program、VB,要求从键盘输入班级人数并输入每位学生的学
*号、姓名、及三门课的成绩,输出学生的学号三门课成绩、平均分以
*及每门课的平均分。
*/

#include <stdio.h>

struct student
{
char stu_id[20];
char stu_name[20];
int score[3];
int aver;
};

int main( )
{
int n;
student stu[10];
int sum = 0;
printf("please input the number of the student of the class:\n");
scanf("%d",&n);
for(int i = 0; i<n; i++)
{
printf("input the %d student id:",i);
scanf("%s",stu[i].stu_id);
printf("input the %d student name:",i);
scanf("%s",stu[i].stu_name);
for(int j = 0; j < 3; j ++)
{
printf("input the %d student's %d score:",i,j);
scanf("%d",&stu[i].score[j]);
sum += stu[i].score[j];
}
stu[i].aver = sum/3;
}