返回列表 發帖

猜拳遊戲 (二)

本帖最後由 tonyh 於 2015-11-6 21:25 編輯

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

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main(){
  5.    re:
  6.    int pla,com;
  7.    string name[]={"剪刀","石頭","布"};
  8.    srand(time(NULL));
  9.    cout<<"請出拳! <1>剪刀 <2>石頭 <3>布 <0>不想玩了  ";
  10.    cin>>pla;
  11.    com=rand()%3+1;
  12.    if(pla==0)
  13.      goto end;
  14.    else if(pla==1||pla==2||pla==3)
  15.      cout<<"你出"<<name[pla-1]<<endl;
  16.    else{
  17.      cout<<"輸入錯誤"<<endl;
  18.      goto re;  
  19.    }   
  20.    if(com==1)
  21.      cout<<"電腦出剪刀!"<<endl;
  22.    else if(com==2)
  23.      cout<<"電腦出石頭!"<<endl;
  24.    else if(com==3)
  25.      cout<<"電腦出布!"<<endl;
  26.    cout<<"結果: ";  
  27.    if(pla==com)
  28.      cout<<"平手"<<endl;
  29.    else if(pla==1&&com==3 || pla==2&&com==1 || pla==3&&com==2)
  30.      cout<<"恭喜您贏了"<<endl;
  31.    else if(pla==1&&com==2 || pla==2&&com==3 || pla==3&&com==1)
  32.      cout<<"恭喜電腦贏了"<<endl;
  33.    goto re;
  34.    end:
  35.    system("pause");   
  36.    return 0;
  37. }
複製代碼
ABCDEFGHIJKLMNOPQRSTUVWXYZ

TOP

11111111111240111111111111

TOP

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

TOP

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

TOP

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

TOP

返回列表