4条回答 默认 最新
- 技术专家团-Plio大咸鱼 2021-09-20 18:11关注
整体修改后如下
其中函数调用的时候不需要在前面写void
有帮助望采纳~#include <stdio.h> #include <stdlib.h> #include <string.h> #define WIDTH 40 #define MIDDLE 25 #define LEFT 5 #define SPACE ' ' #define SIGN '*' void Menu(void); void top_line(char ch); void every_line(char * left, char * right); void show_n_char(char ch,int num); int Max(int a,int b); void Add(void); void Minus(void); void Multiply(void); void Divide(void); void Mixed(void); void main(void) { int choice; Menu(); printf("Please choose one number : "); scanf("%d",&choice); printf("\n"); switch(choice) { case 1: Add();break; case 2: Minus();break; case 3: Multiply();break; case 4: Divide();break; case 5: Mixed();break; case 6: return; default: {printf("\n"),printf("Wrong! Please choose another true number!!\n"),printf("\n"),main();}; } return 0; } void Menu(void) { int spaces; int middle; const char * top = "THE MENU"; const char * choice1 = "1.add(+)"; const char * choice2 = "2.minus(-)"; const char * choice3 = "3.multiply(*)"; const char * choice4 = "4.divide(/)"; const char * choice5 = "5.mixed "; const char * choice6 = "6.Exit"; top_line(SIGN); top_line(SPACE); spaces = (WIDTH - strlen(top)) / 2; putchar(SIGN); show_n_char(SPACE,spaces); printf("%s", top); show_n_char(SPACE,spaces); putchar(SIGN); putchar('\n'); every_line(choice1,choice2); every_line(choice3,choice4); every_line(choice5,choice6); top_line(SPACE); top_line(SIGN); } void top_line(char ch) { printf("%c",SIGN);//putchar(SIGN); show_n_char(ch,WIDTH); putchar(SIGN); putchar('\n'); } void every_line(char * left, char * right) { int middle,spaces; middle = MIDDLE - strlen(left) - LEFT; spaces = WIDTH - strlen(left) - strlen(right)- LEFT - middle; putchar(SIGN); show_n_char(SPACE,LEFT); printf("%s",left); show_n_char(SPACE,middle); printf("%s",right); show_n_char(SPACE,spaces); putchar(SIGN); putchar('\n'); } void show_n_char(char ch,int num)//输出num个ch字符 { int count; for(count = 1; count <= num; count++){ putchar(ch); } } int Max(int a,int b) { int c; c = a + b; if(a < b){a = b;} return a; } void Add(void)//同理注释函数Minus,Multiply,Divide { int x,y,z; int answer = 0; printf("Input number 888 to return Menu!!!\n"); printf("\n"); srand((unsigned)time(NULL)); x = rand()%100 + 1; y = rand()%100 + 1; z = x + y;//随机生成下,一百以内的自然数x和y,并计算他们的和z printf("%d + %d = ",x,y); scanf("%d",&answer); while(answer != 888){ if(z == answer){ x = rand()%100 + 1; y = rand()%100 + 1; z = x + y; printf("%d + %d = ",x,y); } else{ printf("\n"); printf("Wrong!!! Please try again!\n"); printf("%d + %d = ",x,y); } scanf("%d",&answer); };//利用while循环满足多次不相同的计算练习 printf("\n"); main(); } void Minus(void) { int x,y,z; int answer = 0; printf("Input number 888 to return Menu!!!\n"); printf("\n"); srand((unsigned)time(NULL)); x = rand()%100 + 1; y = rand()%100 + 1; z = x + y; x = Max(x,y); y = z - x; z = x - y; printf("%d - %d = ",x,y); scanf("%d",&answer); while(answer != 888){ if(z == answer){ x = rand()%100 + 1; y = rand()%100 + 1; z = x - y; printf("%d - %d = ",x,y); } else{ printf("\n"); printf("Wrong!!! Please try again!\n"); printf("%d - %d = ",x,y); } scanf("%d",&answer); }; printf("\n"); main(); } void Multiply(void) { int x,y,z; int answer = 0; printf("Input number 888 to return Menu!!!\n"); printf("\n"); srand((unsigned)time(NULL)); x = rand()%10 + 1; y = rand()%10 + 1; z = x * y; printf("%d * %d = ",x,y); scanf("%d",&answer); while(answer != 888){ if(z == answer){ x = rand()%10 + 1; y = rand()%10 + 1; z = x * y; printf("%d * %d = ",x,y); } else{ printf("\n"); printf("Wrong!!! Please try again!\n"); printf("%d * %d = ",x,y); } scanf("%d",&answer); }; printf("\n"); main(); } void Divide(void) { int x,y,z; int answer = 0; printf("Input number 888 to return Menu!!!\n"); printf("\n"); srand((unsigned)time(NULL)); x = rand()%10 + 1; y = rand()%10 + 1; z = x * y; x = z; z = x / y; printf("%d / %d = ",x,y); scanf("%d",&answer); while(answer != 888){ if(z == answer){ x = rand()%10 + 1; y = rand()%10 + 1; z = x * y; x = z; z = x / y; printf("%d / %d = ",x,y); } else{ printf("\n"); printf("Wrong!!! Please try again!\n"); printf("%d / %d = ",x,y); } scanf("%d",&answer); }; printf("\n"); main(); } void Mixed(void) { int x,y,z; int i; char c; int answer = 0; printf("Input number 888 to return Menu!!!\n"); printf("\n"); srand((unsigned)time(NULL)); i = rand()%4 + 1; switch(i) { case 1: c = '+'; break; case 2: c = '-'; break; case 3: c = '*'; break; case 4: c = '/'; break; }//随机产生四则运算的符号 switch (c) { case '+': x = rand()%100 + 1; y = rand()%100 + 1; z = x + y; break; case '-': x = rand()%100 + 1; y = rand()%100 + 1; z = x + y; x = Max(x,y); y = z - x; z = x - y; break; case '*': x = rand()%10 + 1; y = rand()%10 + 1; z = x * y; break; case '/': x = rand()%10 + 1; y = rand()%10 + 1; z = x * y; x = z; z = x / y; break; } printf("%d %c %d = ",x,c,y); scanf("%d",&answer); while(answer != 888){ if(z == answer){ i = rand()%4 + 1; switch(i) { case 1: c = '+'; break; case 2: c = '-'; break; case 3: c = '*'; break; case 4: c = '/'; break; } switch (c) { case '+': x = rand()%100 + 1; y = rand()%100 + 1; z = x + y; break; case '-': x = rand()%100 + 1; y = rand()%100 + 1; z = x + y; x = Max(x,y); y = z - x; z = x - y; break; case '*': x = rand()%10 + 1; y = rand()%10 + 1; z = x * y; break; case '/': x = rand()%10 + 1; y = rand()%10 + 1; z = x * y; x = z; z = x / y; break; } printf("%d %c %d = ",x,c,y); } else{ printf("\n"); printf("Wrong!!! Please try again!\n"); printf("%d %c %d = ",x,c,y); } scanf("%d",&answer); };//同样利用while循环满足多次不相同的计算练习 printf("\n"); main(); }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
- ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
- ¥60 pb数据库修改与连接
- ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
- ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
- ¥20 神经网络Sequential name=sequential, built=False
- ¥16 Qphython 用xlrd读取excel报错
- ¥15 单片机学习顺序问题!!
- ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
- ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)