#include <stdio.h> #include <stdlib.h> #define CLS system("cls");//刷新缓冲区 #define STP printf("按任意键继续...");/ getchar(); //需要自己修改/////////////// #define GAME_COUNT 1 // 游戏数量 //自定义添加函数 void cal();//简单计算器 //////////////////////////// //函数声明 无需修改//////////// void GameText(); void GameList(int w); ////////////////////////////// void menu() {//界面菜单 int w; GameText(); while(scanf("%d",&w),w) { getchar(); if(w>=1&&w<=GAME_COUNT) { GameList(w); } printf("错误!输入的超出 1-%d",GAME_COUNT); STP CLS GameText(); } } int main() { menu(); return 0; } //////////////添加新游戏要修改的///////////////// void GameText() { printf("======小游戏百宝箱======/n"); printf("1.简单计算器/n"); //新添加游戏区域 //To Do..... printf("========================/n"); printf("输入0退出/n输入 1-%d 选择菜单项:",GAME_COUNT); } //游戏条目 void GameList(int w) { while(1) { printf("是否要退出该游戏回到主界面吗?需要按0./n"); printf("否则按其他任意键..."); if(getchar()=='0')break; switch(w) { case 1: { CLS cal(); //这里是自己写的函数 上面的CLS 下面的STP CLS 固定写法 不要写错了 STP CLS break; } //To Do..... } } } ////////////////自己写的游戏/////////////// /* 固定格式 void 函数名() { } */ //新添加游戏函数 //To Do..... //简单计算器 void cal() { double a,b,c; char ch; printf("=======简单计算器========/n"); printf("完成两个数加、减、乘、除,/n"); printf("请输入两个数(如:1+2):/n"); scanf("%lf%c%lf",&a,&ch,&b); getchar();//接收掉回车符 switch(ch) { case '+':{ c = a+b; printf("运算结果:%lf/n",c); break; } case '-':{ c= a-b; printf("运算结果:%lf/n",c); break; } case '*':{ c = a*b; printf("运算结果:%lf/n",c); break; } case '/':{ c = a/b; printf("运算结果:%lf/n",c); break; } default:{ printf("对不起你输入的符号不合法!"); } } } ////////////////////////////// 为C语言初学者培养兴趣,简单写了个小框架 暂时保存下~