【項目】
設計一個程序,能重復地在顯示下面的信息:
根據用戶輸入的選項,輸出一句提示性的話語(將來會對應實現某個功能)。輸入0,則退出。
要求將各功能定義專門的函數。
參考解答:
#include <stdio.h>#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選擇錯誤!/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(" 請選擇(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");}總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對武林網的支持。如果你想了解更多相關內容請查看下面相關鏈接
新聞熱點
疑難解答
圖片精選