標題:
[隨堂測驗] 猜拳遊戲 (三)
[打印本頁]
作者:
陳品肇
時間:
2022-2-26 11:32
標題:
[隨堂測驗] 猜拳遊戲 (三)
本帖最後由 陳品肇 於 2022-3-5 10:09 編輯
延續 猜拳遊戲 (二) 的練習,
完成: 1. 判斷輸贏 2. 加上 goto 敘述使可重複遊戲
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
srand(time(NULL));
int player,computer;
string n[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[computer-1]<<endl;
if(player==computer)
cout<<"平手!"<<endl;
else if((player==1 && computer==3)||(player==2 && computer==1)||(player==3 && computer==2))
cout<<"你贏了!"<<endl;
else
cout<<"電腦贏了!"<<endl;
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
許宸瑀
時間:
2022-2-26 11:38
本帖最後由 許宸瑀 於 2022-2-26 11:40 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
srand(time(NULL));
int player,computer;
string n[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[computer-1]<<endl;
if(player==computer)
cout<<"平手!"<<endl;
else if((player==1 && computer==3)||(player==2 && computer==1)||(player==3 && computer==2))
cout<<"你贏了!"<<endl;
else
cout<<"電腦贏了!"<<endl;
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int player, computer;
string meth[3]= {"剪刀", "石頭", "布"};
cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";
re:
cin>>player;
cout<<"你出"+meth[player-1]+"!"<<endl;
srand(time(NULL));
computer = rand()%3+1;
cout<<"電腦"+meth[computer-1]+"!"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
田家齊
時間:
2022-2-26 11:48
本帖最後由 田家齊 於 2022-2-26 12:02 編輯
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
re:
int a,b;
srand(time(NULL));
string x[3]={"剪刀","石頭","布"};
cout<<"請出拳(1)"+x[0]+"(2)"+x[1]+"(3)"+x[2]+":";
cin>>a;
b=rand()%3+1;
cout<<"你出"+x[a-1]+"!"<<endl;
cout<<"電腦出"+x[b-1]+"!"<<endl;
if(a==b)
{
cout<<"平手"<<endl;
} else if(
(a==1&&b==3)|| (a==2&&b==1)|| (a==3&&b==2)
)
{
cout<<"玩家贏"<<endl;
} else
{
cout<<"電腦贏"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
郭博鈞
時間:
2022-2-26 16:07
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
re:
srand(time(NULL));
int player, computer;
string meth[3]={"剪刀","石頭","布"};
cout<<"請出拳! (1)"+meth[0]+"(2)"+meth[1]+"(3)"+meth[2]+": ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<meth[player-1]<<"!"<<endl;
srand(time(NULL));
computer = rand()%3+1;
cout<<"電腦出"+meth[computer-1]+"!"<<endl;
if(computer==player)
cout<<"平手"<<endl;
else if((player==1 && computer==3)||(player==2&&computer==1)||(player==3&&computer==2))
cout<<"你贏了!"<<endl;
else{
cout<<"電腦贏了"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
高鋐鈞
時間:
2022-2-27 21:25
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
re:
int x,y;
string meth[3]= {"剪刀", "石頭", "布"};
cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";
cin>>x;
if(x>3||x<1){
cout<<"輸入錯誤"<<endl;
goto re;
}
cout<<"你出"+meth[x-1]+"";
srand(time(NULL));
y=rand()%3+1;
cout<<"電腦出"+meth[y-1]<<endl;
if(y==x)
cout<<"平手"<<endl;
else if((x==1 && y==3)||(x==2&&y==1)||(x==3&&y==2))
cout<<"你贏了!"<<endl;
else{
cout<<"電腦贏了"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
高昀昊
時間:
2022-2-27 21:55
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
re:
srand(time(NULL));
int player,computer;
string meth[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 ";
cin>>player;
if(player==1||player==2||player==3)
{}else
{
cout<<"輸入錯誤"<<endl;
goto re;
}
computer=rand()%3+1;
cout<<"你出"<<meth[player-1]<<endl;
cout<<"電腦出"<<meth[computer-1]<<endl;
if(player==computer)
cout<<"平手!"<<endl;
else if((player==1 && computer==3)||(player==2 && computer==1)||(player==3 && computer==2))
cout<<"你贏了!"<<endl<<endl;
else
cout<<"電腦贏了!"<<endl<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
孫子傑
時間:
2022-3-1 22:10
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
re:
int x, z;
string meth[3]= {"剪刀", "石頭", "布"};
cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";
cin>>x;
if(x>3||x<1){
cout<<"輸入錯誤"<<endl;
goto re;
}
cout<<"你出"+meth[x-1]+"!"<<endl;
srand(time(NULL));
z = rand()%3+1;
cout<<"電腦出"+meth[z-1]+"!"<<endl;
if(x==z)
{
cout<<"平手"<<endl;
}else if((x==1 && z==3)||(x==2 && z==1)||(x==3 && z==2))
{
cout<<"你贏了!"<<endl;
}else
{
cout<<"電腦贏了!"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
林鴻慶
時間:
2022-3-5 09:04
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
srand(time(NULL));
int player,computer;
string n[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[computer-1]<<endl;
if(player==computer)
cout<<"平手!"<<endl;
else if((player==1 && computer==3)||(player==2 && computer==1)||(player==3 && computer==2))
cout<<"你贏了!"<<endl;
else
cout<<"電腦贏了!"<<endl;
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
柳侑辰
時間:
2022-3-5 09:46
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int player=0,computer=0;
string go[3]={"剪刀","石頭","布"};
cout<<"請出拳! (1)"+go[0]+"(2)"+go[1]+"(3)"+go[2]+":";
cin>>player;
cout<<"你出"+go[player-1]+"!"<<endl;
srand(time(NULL));
computer=rand()%3+1;
cout<<"電腦"+go[computer-1]+"!"<<endl;
if(player == computer)
{
cout<<"平手!"<<endl<<endl;
}else if((player==1 && computer==3)||(player==2 && computer==1)||(player==3 && computer==2))
{
cout<<"你贏了!"<<endl<<endl;
}else
{
cout<<"電腦贏了!"<<endl<<endl;
}goto re;
system("pause");
return 0;
}
複製代碼
作者:
徐譽豈
時間:
2022-3-5 10:10
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
srand(time(NULL));
int player,computer;
string n[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[computer-1]<<endl;
if(player==computer)
cout<<"平手!"<<endl;
else if((player==1 && computer==3)||(player==2 && computer==1)||(player==3 && computer==2))
cout<<"你贏了!"<<endl;
else
cout<<"電腦贏了!"<<endl;
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
曾善勤
時間:
2022-3-5 10:11
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
srand(time(NULL));
int player,computer;
string n[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[computer-1]<<endl;
if(player==computer)
cout<<"平手!"<<endl;
else if((player==1 && computer==3)||(player==2 && computer==1)||(player==3 && computer==2))
cout<<"你贏了!"<<endl;
else
cout<<"電腦贏了!"<<endl;
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
黃奕澄
時間:
2022-3-5 10:13
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
srand(time(NULL));
int player,computer;
string n[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[computer-1]<<endl;
if(player==computer)
cout<<"平手!"<<endl;
else if((player==1 && computer==3)||(player==2 && computer==1)||(player==3 && computer==2))
cout<<"你贏了!"<<endl;
else
cout<<"電腦贏了!"<<endl;
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
林紘憲
時間:
2022-3-5 10:13
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
srand(time(NULL));
int player,computer;
string n[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[computer-1]<<endl;
if(player==computer)
cout<<"平手!"<<endl;
else if((player==1 && computer==3)||(player==2 && computer==1)||(player==3 && computer==2))
cout<<"你贏了!"<<endl;
else
cout<<"電腦贏了!"<<endl;
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
鍾易澄
時間:
2022-3-5 10:15
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
srand(time(NULL));
int player,computer;
string n[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[computer-1]<<endl;
if(player==computer)
cout<<"平手!"<<endl;
else if((player==1 && computer==3)||(player==2 && computer==1)||(player==3 && computer==2))
cout<<"你贏了!"<<endl;
else
cout<<"電腦贏了!"<<endl;
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2