fork download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <windows.h>
  4. #include <time.h>
  5. #define N 3//定義一個常數N,用來當做題目的初始設定
  6. void Game(int &i);//遊戲程式
  7. void Menu(char &op);//選單畫面
  8. void Clock(void);//倒數計時器
  9. void Result(int total);//顯示結果
  10. void main(void)
  11. {
  12. char op;//功能選項
  13. int i=0,total=0;//計數器i,每過一關加一;total成績
  14. while(1)//程式永遠執行
  15. {
  16. Menu(op);//選單畫面
  17. switch(op)
  18. {
  19. case 'Y': //輸入Y 進行遊戲
  20. Game(i);//進入遊戲程式
  21. total=N+i;//計算成績
  22. Result(total);//結果分析
  23. system("pause");//暫停畫面
  24. system("cls");//清除畫面
  25. break;
  26. case 'N': //輸入N 離開
  27. printf("*********************\n");
  28. printf("* 感謝您的使用^^ *\n");
  29. printf("* bye~ bye~ *\n");
  30. printf("*********************\n");
  31. system("pause");
  32. exit(1);//離開
  33. break;
  34. default://錯誤訊息
  35. printf("*********************\n");
  36. printf("*輸入錯誤 請重新輸入*\n");
  37. printf("*********************\n");
  38. break;
  39. }//switch
  40. }//while(1)
  41. }//end main
  42. void Menu(char &op){
  43. printf("******************************\n");
  44. printf("** 歡迎使用本記憶力測驗程式 **\n");
  45. printf("******************************\n");
  46. printf("本程式會先顯示一串隨機組合的英文字串10秒\n");
  47. printf("然後要求你輸入該字串輸入正確,會加長英文\n");
  48. printf("字串長度,並繼續測驗輸入錯誤,則結束程式\n");
  49. printf("是否進行測驗(Y/N)?");
  50. printf("請輸入選項\n");
  51. scanf(" %c",&op);//玩家輸入選項
  52. }//Menu
  53. void Game(int &i){//遊戲程式
  54. char Quiz[12]={};//題目
  55. char Ans[12]={};//玩家輸入答案
  56. int j;//計數器j
  57. srand(time(NULL));//打亂亂數
  58. for(j=0;j<N+i;j++){//設定題目
  59. Quiz[j]=(65+rand()%26);
  60. }
  61. printf("*** %s ***\n",Quiz);//列印題目
  62. Clock();//倒數計時
  63. system("cls");//清除畫面
  64. printf("Time up!\n");
  65. printf("請輸入解答");
  66. scanf("%s",Ans);//玩家輸入答案
  67. if(strncmp(Quiz,Ans,N+i)==0)//驗證答案
  68. {
  69. if(N+i<11)//終止條件
  70. {
  71. i++;
  72. Game(i);//答對->繼續下一關
  73. }else{
  74. printf("測驗結束!");
  75. }
  76. }else{
  77. printf("測驗結束!\n");
  78. }//if-else
  79. }//Game
  80. void Clock(void){//倒數計時器
  81. int k;
  82. for(k=10;k>0;k--)
  83. {
  84. printf("剩下 %d 秒\n",k);//顯示剩餘的秒數
  85. Sleep(1000);//暫停一秒
  86. }
  87. }//Clock
  88. void Result(int total){//結果分析
  89. printf("你的記憶力指數是%d",total);
  90. if(total<5){
  91. printf("你的記憶力不太好喔!\n");
  92. }else{
  93. if(total<8){
  94. printf("你的記憶力不錯喔!\n");
  95. }else{
  96. printf("你的記憶力太棒了!\n");
  97. }
  98. }
  99. }//Result
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:3:21: error: windows.h: No such file or directory
prog.c:6: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
prog.c:7: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
prog.c:10: warning: return type of ‘main’ is not ‘int’
prog.c: In function ‘main’:
prog.c:16: warning: implicit declaration of function ‘Menu’
prog.c:20: warning: implicit declaration of function ‘Game’
prog.c:23: warning: ignoring return value of ‘system’, declared with attribute warn_unused_result
prog.c:24: warning: ignoring return value of ‘system’, declared with attribute warn_unused_result
prog.c:31: warning: ignoring return value of ‘system’, declared with attribute warn_unused_result
prog.c: At top level:
prog.c:42: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
prog.c:53: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
prog.c: In function ‘Clock’:
prog.c:85: warning: implicit declaration of function ‘Sleep’
stdout
Standard output is empty