Board logo

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

作者: 鄭繼威    時間: 2023-6-2 21:06     標題: 猜拳遊戲 (二)

陣列存放 "剪刀" "石頭" "布",改寫上一個程式-猜拳遊戲 (一)
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     srand(time(NULL));
  8.     int player,computer;
  9.     string n[]={"剪刀","石頭","布"};
  10.     cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
  11.     cin>>player;
  12.     computer=rand()%3+1;   //1~3
  13.     cout<<"你出"<<n[player-1]<<endl;
  14.     cout<<"電腦出"<<n[computer-1]<<endl;
  15.     system("pause");   
  16.     return 0;
  17. }
複製代碼

作者: 蔡沛倢    時間: 2023-6-8 16:59

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

作者: 呂宗晉    時間: 2023-6-9 17:24

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

作者: 何權晉    時間: 2023-6-9 20:47

  1. #include<iostream>
  2. #include<ctime>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(time(NULL));
  7.     int p,c;
  8.     cout<<"ROCK PAPER SCISSORS 1v1 WITH PC!!"<<endl;
  9.     string n[]={"Rock!","Paper!","Scissors!"};
  10.     cout<<"Rock Paper Scissors! (1)Rock (2)Paper (3)Scissors";
  11.     cin>>p;
  12.     c=rand()%3+1;
  13.     cout<<"You picked: "<<n[p-1]<<endl;
  14.     cout<<"The PC Picked: "<<n[c-1]<<endl;
  15. system("pause");
  16. return 0;
  17. }
複製代碼

作者: 鄭繼威    時間: 2023-6-9 20:48

4
作者: 黃子豪    時間: 2023-6-9 20:49

  1. #include<iostream>
  2. #include<ctime>
  3. using namespace std;

  4. int main(){
  5.    
  6.     srand(time(NULL));
  7.     int player, computer;
  8.     string a[3]={"剪刀", "石頭", "布"};
  9.     cout<<"請出拳! (1)剪刀(2)石頭(3)布";
  10.     cin>>player;
  11.    
  12.     cout<<"你出"<<a[player-1]<<endl;
  13.    
  14.     computer=rand()%3+1;
  15.     cout<<"電腦出"<<a[computer-1]<<endl;

  16.    
  17.     system("pause");
  18.     return 0;
  19. }
複製代碼

作者: 廖秝瑜    時間: 2023-6-9 20:50

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

作者: 張絜晰    時間: 2023-6-9 20:52

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

作者: 呂得銓    時間: 2023-6-16 16:33

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

作者: 盧玄皓    時間: 2023-6-16 19:39

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

作者: 黃品禎    時間: 2023-7-1 16:42

  1. #include<cstdlib>
  2. #include<iostream>
  3. #include<ctime>
  4. using namespace std;

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

作者: 吳柏潁    時間: 2023-8-3 16:20

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

作者: 邱品惟    時間: 2023-8-8 20:34

  1. #include<iostream>
  2. #include<ctime>
  3. using namespace std;
  4. int main()
  5. {
  6.     int player,computer,again;
  7.     cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
  8.     cin>>player;
  9.     computer=rand()%3+1;
  10.     if(player<=3&&player>=1)
  11.     {
  12.         string n[]={"剪刀","石頭","布"};
  13.         cin>>player;
  14.         computer=rand()%3+1;
  15.         cout<<"你出"<<n[player-1]<<endl;
  16.         cout<<"電腦出"<<n[computer-1]<<endl;
  17.     }
  18.     else
  19.     {
  20.         cout<<"我的鞭子在哪裡"<<endl;
  21.     }
  22.     system("pause");   
  23.     return 0;
  24. }
複製代碼

作者: 朱奕祈    時間: 2024-2-19 19:53

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





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