请大佬们帮我改一下,总是出错。。。


#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int a,b,answer,ans,i,sum=0,choice,j;
struct student
 {
     int no;
     char name[20];
     int mark;
 }s[5],stu;


struct problem
 {
     int m;
     int n;
     char op;
     int AA;
 }p[5];
struct prob
 {
     int m;
     int n;
     char op;
     int AA;
     int flag;
 }pa[5];

   void menu();
   void rannum();
   void addproblem();
   void subproblem();
   void judje();
   void printfPA();
   void printS();
int main()
{
    srand(time(NULL));
    printf("please inter your name!\n");
    scantf("%d",&stu.no);
    j=0;
    while(stu.no>0)

    scantf("%s",stu.name);

    menu();
    scantf("%d",&choice);
    switch(choice)
{
    case 0:
    exit(1);
    break;
    case 1:
    for (i=0;i<5;i++)
{//出题
    rannum();
    addproblem();
    p[i].m=a; pa[i].m=a;
    p[i].n=b; pa[i].n=b;
    p[i].op='+';pa[i].op='+';
    p[i].AA=answer;
    scantf("%d",&ans);
    pa[i].AA=ans;
    judje();
};
break;
 case 2:
    for (i=0;i<5;i++)
{//出题
    rannum();
    subproblem();
    p[i].m=a; pa[i].m=a;
    p[i].n=b; pa[i].n=b;
    p[i].op='+';pa[i].op='+';
    p[i].AA=answer;
    scantf("%d",&ans);
    pa[i].AA=ans;
    judje();
};
break;
}
printPA();
  s[j].no=stu.no;
strcpy(s[j].name,stu.name);
s[j].mark=stu.mark;
j++;
printf("please enter your no & your name");
scantf("%d",&stu.no);
}
printfS();
return 0;
}
void menu()
{
    printf("*****************/n");
    printf("welcome/n");
    printf("*1.add 2.sub 3.mul 4.div 5.mod 6.exit*\n");
    printf("*****************/n");
    printf("please enter your choice");
}
void rannum()
{
        printf("第%d题:",i);
        a=rand()%10+1;
        b=rand()%10+1;
}
void addproblem()
{
    answer=a+b;
    printf("%d + %d = ",a,b);
    scantf("%d",ans);
}
void subproblem()
{
    answer=a-b;
    printf("%d-%d=",a,b);
}
void judje()
{
if (answer=ans)
{
printf("Yes!\n");
sum++;
}
else
printf ("No!\n");

printf("做对了%d道题,共得到了%d分,得分率为%.2f !",sum,sum*10,(1.0*sum)/10);
}
void printfPA()
{
    int i;
    FILE *fp;
    printf("This is your exam paper!\n");
    for(i=0;i<5;i++)
         printf("%d %c %d = %d\n",pa[i].m,pa[i].n,pa[i].AA);
    if((fp=fopen("data.txt","w"))==NULL)
    {
        printf("Cannot open file");
        exit(1);
    }
    for(i=0;i<5;i++)
    frintf(fp,"%d %c %d = %d\n",pa[i].m,pa[i].n,pa[i].AA);
    fclose(fp);
    return;
}
void printS()
{
    int i;
    FILE *fp;
    printf("This is class score list!\n");
    for(i=0;i<5;i++)
        printf("%d %s %d \n",s[i].no,s[i].name,s[i].mark);
    if((fp=fopen("data.txt","w"))==NULL)
    {
        printf("Cannot open file");
        exit(1);
    }
    for(i=0;i<5;i++)
    frintf(fp,"%d %s %d \n",s[i].no,s[i].name,s[i].mark);
    fclose(fp);
    return;
}

 

1、scantf 应为 scanf:在 main 函数中,将 scantf 改为 scanf,因为正确的函数名是 scanf,用于从标准输入读取数据;
2、循环问题:在 main 函数中,while 循环的条件是 stu.no > 0,但是在循环内部没有更新 stu.no 的值,导致循环将无限进行下去。您需要在循环内部更新 stu.no 的值;
3、judje 函数中的条件判断错误:在 judje 函数中,条件判断应使用相等运算符 == 而不是赋值运算符 =。将 if (answer = ans) 修改为 if (answer == ans);
4、文件写入问题:在 printfPA 和 printS 函数中,使用了 frintf,应该将其更正为 fprintf,同时还应将文件打开模式从 "w" 修改为 "a",以便在写入文件时不会覆盖已有内容;
5、printf 函数中的转义字符错误:在 menu 函数中,将 *****************/n 修改为 *****************\n,以正确使用换行符;
6、stu.mark 未初始化:在 main 函数中,stu.mark 未被初始化。您可以在 stu.no 的输入之后,将 stu.mark 初始化为零。