蝴蝶是我 2023-02-23 23:24 采纳率: 76.5%
浏览 12
已结题

嵌套函数无法实现,直接退出

为什么输入1后无法进入requestion函数,而是直接退出

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
//结构
struct system{
    char question[60];
    char A[20];
    char B[20];
    char C[20];
    char D[20];
    char answer[60];
};
int NUM=1;
struct system t[1000];
//函数们
void menu();
void requestions();//问题
void test();//考试系统
int randnumber();//随机数

int main()  // 菜单
{
    int n;
    printf("--------------菜单--------------\n");
    printf("请输入数字选择相应操作\n");
    
    printf("1.更新题库<题库数为%d>\n",NUM);
    printf("2.考试系统\n");
    printf("--------------------------------\n");
    scanf("%d",&n);
    if(n==1)
    void requestion();
    
    if(n==2)
    {
        void test();
    }
    return 0;
}
int randnumber()
{   int i;
    srand((unsigned)time(NULL));
    
        i=rand()%NUM+1;
    return i;
}
void requestion(){
    
    int i,n;
    printf("请问您此次想增加多少题?\n");
    scanf("%d",&n);
    printf("请依次输入题目、四个选项及其答案\n");
    printf("输入格式如下“1+1=? 1 2 3 4 B");
    for(i=NUM;i<NUM+n;i++){
        scanf("%s%s%s%s%s%s",t[i].question,t[i].A,t[i].B,t[i].C,t[i].D,t[i].answer);
    }
    NUM=i;
    
    
}
void text(){
    int n,i,count=0,s;
    char a[20];
    printf("请输入做题数\n");
    scanf("%d",&n);
    for(i=0;i<n;i++){
        s=randnumber();
        printf("%s\n",t[s].question);
        printf("A.%s   B.%s   C.%s   D.%s\n",t[s].A,t[s].B,t[s].C,t[s].D);
        printf("请输入您的答案\n");
        scanf("%s",a);
        if(strcmp(a,t[s].answer)==0)
        count++;
    }
    printf("您的最终得分是:%d",count);
}

  • 写回答

2条回答 默认 最新

  • 菜鸟才能学的更多 2023-02-24 00:17
    关注

    在 main() 函数中,当用户输入 n=1 时,你使用了 void requestion() 来调用函数,应该是想调用 requestion() 函数,但是语法错误导致编译错误。正确的写法是 requestion(),去掉 void 关键字即可。同理,当用户输入 n=2 时,也应该是调用 test() 函数,而不是 void test()

    int main()  // 菜单
    {
        int n;
        printf("--------------菜单--------------\n");
        printf("请输入数字选择相应操作\n");
        
        printf("1.更新题库<题库数为%d>\n",NUM);
        printf("2.考试系统\n");
        printf("--------------------------------\n");
        scanf("%d",&n);
        if(n==1)
            requestion();
        
        if(n==2)
        {
            test();
        }
        return 0;
    }
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月4日
  • 已采纳回答 2月24日
  • 创建了问题 2月23日