本帖最後由 tonyh 於 2016-8-27 11:20 編輯
以陣列存放 "剪刀" "石頭" "布", 重寫上一個程式.- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- srand(time(NULL));
- int player,computer;
- string name[3]={"剪刀","石頭","布"};
- cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
- cin>>player;
- computer=rand()%3+1;
- cout<<"你出"<<name[player-1]<<endl;
- cout<<"電腦出"<<name[computer-1]<<endl;
- system("pause");
- return 0;
- }
複製代碼 |