打豆豆游戏c语言编程,C语言程序打豆豆(函数版)
【項(xiàng)目】
設(shè)計(jì)一個(gè)程序,能重復(fù)地在顯示下面的信息:
1. 吃飯
2. 睡覺
3. 打豆豆
0. 退出
請(qǐng)選擇(0-3):
根據(jù)用戶輸入的選項(xiàng),輸出一句提示性的話語(將來會(huì)對(duì)應(yīng)實(shí)現(xiàn)某個(gè)功能)。輸入0,則退出。
要求將各功能定義專門的函數(shù)。
參考解答:
#include
#define EAT '1'
#define SLEEP '2'
#define HITDOUDOU '3'
#define CRY '4'
#define WITHDRAW '0'
char getChoice();
void eat();
void sleep();
void hitdoudou();
void cry();
int main()
{
char cChioce;
while(1)
{
cChioce = getChoice();
if (cChioce==EAT)
eat();
else if (cChioce==SLEEP)
sleep();
else if (cChioce==HITDOUDOU)
hitdoudou();
else if (cChioce==CRY)
cry();
else if (cChioce==WITHDRAW)
break;
else
{
printf("\007選擇錯(cuò)誤!\n");
}
}
return 0;
}
char getChoice()
{
char c;
printf("\n ********************\n");
printf(" * 1. 吃飯 *\n");
printf(" * 2. 睡覺 *\n");
printf(" * 3. 打豆豆 *\n");
printf(" * 4. 找豆豆媽訴苦 *\n");
printf(" * 0. 退出 *\n");
printf(" ********************\n");
printf(" 請(qǐng)選擇(0-4):");
fflush(stdin);
scanf("%c", &c);
return c;
}
void eat()
{
printf(" 我吃吃吃... ...\n");
}
void sleep()
{
printf(" 我睡覺覺... ...\n");
}
void hitdoudou()
{
printf(" 我打打打... ...\n");
}
void cry()
{
printf(" 哇! 你家豆豆骨頭硬,害得我手疼... ...\n");
}
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
總結(jié)
以上是生活随笔為你收集整理的打豆豆游戏c语言编程,C语言程序打豆豆(函数版)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 东南大学c语言下学期期末考试题,东南大学
- 下一篇: 简述python程序的运行原理_谈谈 P