Board logo

標題: 猜拳遊戲 (二) [打印本頁]

作者: 陳品肇    時間: 2022-2-26 10:36     標題: 猜拳遊戲 (二)

本帖最後由 陳品肇 於 2022-2-26 11:30 編輯

以陣列存放 "剪刀" "石頭" "布", 改寫上一個程式.
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int player, computer;
  8.     string meth[3]= {"剪刀", "石頭", "布"};
  9.     cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";

  10.     cin>>player;
  11.     cout<<"你出"+meth[player-1]+"!"<<endl;
  12.     srand(time(NULL));
  13.     // 產出 1~3 亂數
  14.     computer = rand()%3+1;   
  15.     cout<<"電腦"+meth[computer-1]+"!"<<endl;
  16.     system("pause");
  17.     return 0;
  18. }
複製代碼

作者: 黃奕澄    時間: 2022-2-26 11:33

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int player, computer;
  8.     string meth[3]= {"剪刀", "石頭", "布"};
  9.     cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";

  10.     cin>>player;
  11.     cout<<"你出"+meth[player-1]+"!"<<endl;
  12.     srand(time(NULL));
  13.     computer = rand()%3+1;   
  14.     cout<<"電腦"+meth[computer-1]+"!"<<endl;
  15.     system("pause");
  16.     return 0;
  17. }
複製代碼

作者: 曾善勤    時間: 2022-2-26 11:35

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int player, computer;
  8.     string meth[3]= {"剪刀", "石頭", "布"};
  9.     cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";

  10.     cin>>player;
  11.     cout<<"你出"+meth[player-1]+"!"<<endl;
  12.     srand(time(NULL));
  13.     computer = rand()%3+1;   
  14.     cout<<"電腦"+meth[computer-1]+"!"<<endl;
  15.     system("pause");
  16.     return 0;
  17. }
複製代碼

作者: 許馹東    時間: 2022-2-26 11:35

  1.     #include<iostream>
  2.     #include<cstdlib>
  3.     using namespace std;
  4.     int main()
  5.     {
  6.         re:
  7.           int x, z;
  8.     string meth[3]= {"剪刀", "石頭", "布"};
  9.     cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";

  10.     cin>>x;
  11.     cout<<"你出"+meth[x-1]+"!"<<endl;
  12.     srand(time(NULL));
  13.     z = rand()%3+1;   
  14.     cout<<"電腦"+meth[z-1]+"!"<<endl;
  15.         goto re;
  16.         system("pause");   
  17.         return 0;
  18.     }
複製代碼

作者: 鍾易澄    時間: 2022-2-26 11:35

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int player, computer;
  8.     string meth[3]= {"剪刀", "石頭", "布"};
  9.     cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";

  10.     cin>>player;
  11.     cout<<"你出"+meth[player-1]+"!"<<endl;
  12.     srand(time(NULL));
  13.     computer = rand()%3+1;   
  14.     cout<<"電腦"+meth[computer-1]+"!"<<endl;
  15.     system("pause");
  16.     return 0;
  17. }
複製代碼

作者: 林紘憲    時間: 2022-2-26 11:36

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int player, computer;
  8.     string meth[3]= {"剪刀", "石頭", "布"};
  9.     cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";

  10.     cin>>player;
  11.     cout<<"你出"+meth[player-1]+"!"<<endl;
  12.     srand(time(NULL));
  13.     // 產出 1~3 亂數
  14.     computer = rand()%3+1;   
  15.     cout<<"電腦"+meth[computer-1]+"!"<<endl;
  16.     system("pause");
  17.     return 0;
  18. }
複製代碼

作者: 孫子傑    時間: 2022-2-26 11:38

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int player, computer;
  8.     string meth[3]= {"剪刀", "石頭", "布"};
  9.     cout<<"請出拳! (1)"+meth[0]+"(1)"+meth[1]+"(2)"+meth[2]+":";
  10.     cin>>player;
  11.     cout<<"你出"+meth[player-1]+"!"<<endl;
  12.     srand(time(NULL));
  13.     computer = rand()%3+1;   
  14.     cout<<"電腦"+meth[computer-1]+"!"<<endl;
  15.     system("pause");
  16.     return 0;
  17. }
複製代碼

作者: 許宸瑀    時間: 2022-2-26 11:38

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int player, computer;
  8.     string meth[3]= {"剪刀", "石頭", "布"};
  9.     cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";

  10.     cin>>player;
  11.     cout<<"你出"+meth[player-1]+"!"<<endl;
  12.     srand(time(NULL));
  13.     computer = rand()%3+1;   
  14.     cout<<"電腦"+meth[computer-1]+"!"<<endl;
  15.     system("pause");
  16.     return 0;
  17. }
複製代碼

作者: 田家齊    時間: 2022-2-26 11:40

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.   int a,b;
  8.   srand(time(NULL));
  9.   string x[3]={"剪刀","石頭","布"};
  10.   cout<<"請出拳(1)"+x[0]+"(2)"+x[1]+"(3)"+x[2]+":";
  11.   cin>>a;
  12.   b=rand()%3+1;
  13.   cout<<"你出"+x[a-1]+"!"<<endl;
  14.   cout<<"電腦出"+x[b-1]+"!"<<endl;
  15. system("pause");
  16. return 0;
  17. }  
複製代碼

作者: 徐譽豈    時間: 2022-2-26 11:45

  1. include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int player,computer;
  7.     string meth[]={"剪刀","石頭","布"};
  8.     cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+":";
  9.     cin>>player;
  10.     cout<<"你出"+meth[player-1]+"!"<<endl;
  11.     srand(time(NULL));
  12.     computer = rand()%3+1;
  13.     cout<<"電腦"+meth[computer-1]+"!"<<endl;  
  14.     system("pause");
  15.     return 0;
  16. }
複製代碼

作者: 高鋐鈞    時間: 2022-2-26 11:45

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.    
  8.     int x,y;
  9.     string meth[3]= {"剪刀", "石頭", "布"};
  10.     cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";
  11.     cin>>x;
  12.    
  13.     cout<<"你出"+meth[x-1]+"";
  14.     srand(time(NULL));   
  15.     y=rand()%3+1;
  16.     cout<<"電腦出"+meth[y-1]<<endl;
  17.     system("pause");   
  18.     return 0;
  19. }
複製代碼

作者: 郭博鈞    時間: 2022-2-26 11:46

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.    
  8.     int player, computer;
  9.      string meth[3]={"剪刀","石頭","布"};
  10.     cout<<"請出拳!   (1)"+meth[0]+"(2)"+meth[1]+"(3)"+meth[2]+":  ";
  11.     cin>>player;
  12.     computer=rand()%3+1;
  13.     cout<<"你出"<<meth[player-1]<<"!"<<endl;
  14.     srand(time(NULL));
  15.      computer = rand()%3+1;
  16.     cout<<"電腦出"+meth[computer-1]+"!"<<endl;
  17.     system("pause");   
  18.     return 0;
  19. }
複製代碼

作者: 林鴻慶    時間: 2022-3-5 09:14

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int player, computer;
  8.     string meth[3]= {"剪刀", "石頭", "布"};
  9.     cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";

  10.     cin>>player;
  11.     cout<<"你出"+meth[player-1]+"!"<<endl;
  12.     srand(time(NULL));
  13.     computer = rand()%3+1;   
  14.     cout<<"電腦"+meth[computer-1]+"!"<<endl;
  15.     system("pause");
  16.     return 0;
  17. }
複製代碼

作者: 柳侑辰    時間: 2022-3-5 09:37

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int player,computer;
  7.     string go[3]={"剪刀","石頭","布"};
  8.     cout<<"請出拳! (1)"+go[0]+"(2)"+go[1]+"(3)"+go[2]+":";
  9.     cin>>player;
  10.     cout<<"你出"+go[player-1]+"!"<<endl;
  11.     srand(time(NULL));
  12.     computer=rand()%3+1;
  13.     cout<<"電腦"+go[computer-1]+"!"<<endl;
  14.     system("pause");   
  15.     return 0;
  16. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2