返回列表 發帖

猜拳遊戲 (二)

陣列存放 "剪刀" "石頭" "布",改寫上一個程式-猜拳遊戲 (一)
  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. }
複製代碼

  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. }
複製代碼

TOP

  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. }
複製代碼

TOP

  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. }
複製代碼

TOP

  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. }
複製代碼

TOP

  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. }
複製代碼

TOP

  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. }
複製代碼

TOP

  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;}
複製代碼
Attention Seeker </3

TOP

  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. }
複製代碼

TOP

  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. }
複製代碼

TOP

4

TOP

  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. }
複製代碼

TOP

  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. 複製代碼
複製代碼

TOP

  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. }
複製代碼

TOP

返回列表