返回列表 發帖

猜拳遊戲 (二)

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

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

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(time(NULL));
  7.     re:
  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.     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.     srand (time(NULL));
  8.     pun:
  9.     int d,f;
  10.     string n[]={"剪刀","石頭","布"};
  11.     cout<<"還不快出 1.剪刀 2.石頭 3.布"<<endl;
  12.     cin>>d;
  13.     f=rand()%3+1;
  14.     cout<<"你出"<<n[d-1]<<endl;
  15.    
  16.     cout<<"電腦出"<<n[f-1]<<endl;
  17.     goto pun;
  18.    
  19.    
  20.     system("pause");
  21.     return 0;   
  22. }
複製代碼
hahahahahahahaha

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.     re:
  10.     string n[]={"剪刀","石頭","布"};
  11.     cout<<"請出拳!  <1>剪刀 <2>石頭 <3>布";
  12.     cin>>player;
  13.     computer=rand()%3+1
  14.     cout<<"你出"<<n[player-1]<<"!"<<endl;
  15.     cout<<"電腦出"<<n[computer-1]<<"!"<<endl;
  16.     goto re;
  17.     system("pause");
  18.     return 0;
  19. }
複製代碼
Huang chenhao

TOP

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

TOP

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

TOP

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

TOP

返回列表