返回列表 發帖

猜拳遊戲 (二)

本帖最後由 陳品肇 於 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. }
複製代碼

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

返回列表