fork download
  1. #include <iostream>
  2. #include <stdlib.h> // 亂數函數的表頭檔
  3. #include <time.h> // 時間函數表頭檔
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. int n = 8; //神秘數字n
  9. int a; //輸入餐猜測數字
  10. int count = 0; //計數器counter
  11.  
  12. start:
  13. cout << "輸入1-10, 看看你能不能猜到神祕數字: ";
  14. cin >> a;
  15. cout << endl;
  16.  
  17. if(a > n){
  18. cout << "錯! 比" << a << "小" << endl;
  19. count++; //count=count+1
  20. if (count >= 3){
  21. goto end;
  22. }
  23. goto start;
  24. }
  25. else if (a < n){
  26. cout << "錯! 比" << a << "大" << endl;
  27. count++; ////count=count+1
  28. if (count >= 3){
  29. goto end;
  30. }
  31. goto start;
  32. }
  33. else{
  34. cout << "厲害! 猜對了" << endl;
  35. goto end;
  36. }
  37.  
  38. end:
  39. cout << "遊戲結束" << endl;
  40. system("pause");
  41. return 0;
  42. }
Success #stdin #stdout #stderr 0s 4344KB
stdin
8
stdout
輸入1-10, 看看你能不能猜到神祕數字: 
厲害! 猜對了
遊戲結束
stderr
sh: 1: pause: not found