第十一題
#include
#include
#include
int main(void){
char gesture[4][10] = {"","剪刀","石頭","布"};
int iPlayer, iComp;
srand(time(NULL));
while(1)
{
iComp = rand()%3 + 1;
printf("\1-剪刀 2-石頭 3-布:\n");
scanf("%d", &iPlayer);
if(iPlayer < 1 || iPlayer > 3)
{
printf("Invalid input!\n");
return 1;
}
printf("你:%s\t電腦: %s\n",gesture[iPlayer], gesture[iComp]);
if(iPlayer - iComp == 0)
printf("平手!\n");
else if(iPlayer - iComp == 1)
printf("你贏了\n");
else if(iPlayer - iComp == -1)
printf("我輸了 呼!\n");
}
system("pause");return 0;
}
留言
張貼留言