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