|
发表于 2022-12-1 14:14:14
|
显示全部楼层
本楼为最佳答案
- #include <stdio.h>
- int open = 0; /*玩具是否开启*/
- const char * stories[3] = {"小猫钓鱼", "龟兔赛跑", "乌鸦喝水"};
- /*讲的故事*/
- void open_close() { /*开或关*/
- if (open == 0) printf("已打开,欢迎使用!\n");
- else printf("已关闭,再见!\n");
- open = !open;
- }
- void tell_stories() { /*讲故事*/
- if (!open) {
- puts("错误!您没有打开玩具,请输入1打开!");
- return;
- }
- while (1) {
- for (int i = 0; i < 3; ++i) {
- printf("正在播放:%s\n", stories[i]);
- /*询问是否播放下一个故事*/
- printf("是否播放下一个故事:%s?(1表示继续,0表示结束)", stories[(i + 1) % 3]);
- int opt;
- scanf("%d", &opt);
- if (!opt) return; /*不想听了就退出*/
- }
- }
- }
- void sing() { /*唱歌*/
- if (!open) {
- puts("错误!您没有打开玩具,请输入1打开!");
- return;
- }
- while (1) {
- printf("正在播放:数鸭歌...\n");
- printf("是否继续播放?(1表示继续,0表示结束)");
- int opt;
- scanf("%d", &opt);
- if (!opt) return; /*不想听了就退出*/
- }
- }
- int main() {
- printf("欢迎使用摇摆鹅玩具系统!\n");
- while (1) {
- int opt;
- printf("输入1打开或关闭,输入2讲故事,输入3唱歌:");
- scanf("%d", &opt);
- switch (opt) {
- case 1: open_close(); break;
- case 2: tell_stories(); break;
- case 3: sing(); break;
- default: printf("请输入正确的指令!\n");
- }
- }
- }
复制代码 |
|