本帖最後由 蔡依宸 於 2018-11-17 15:54 編輯
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int player,computer;
- cout<<"請出拳(1)剪刀 (2)石頭 (3)布"<<endl;
- cin>>player;
- if(player==1)
- {
- cout<<"你出剪刀"<<endl;
- }else if(player==2)
- {
- cout<<"你出石頭"<<endl;
- }else
- {
- cout<<"你出布"<<endl;
- }
-
- srand(time(NULL));
- computer=rand()%3+1;
- if(computer==1)
- {
- cout<<"電腦出剪刀"<<endl;
- }else if(computer==2)
- {
- cout<<"電腦出石頭"<<endl;
- }else
- {
- cout<<"電腦出布"<<endl;
- }
- if(player==computer)
- {
- cout<<"平手"<<endl;
-
- }if((player==1 && computer==3)||(player==2 && computer==1)||(player==3 && computer==2))
- {
- cout<<"你贏了"<<endl;
- }else
- {
- cout<<"你輸了"<<endl;
- }
- system("pause");
- return 0;
- }
複製代碼 |