Re: [問題] 小遊戲大問題

看板C_and_CPP (C/C++)作者 (nahgnimiast)時間16年前 (2009/04/03 23:20), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
無聊中.... #include <time.h> #include <stdio.h> void main() { int times; int win = 0; int lost = 0; int input; int compare; srand(time(NULL)); printf("幾次?\n"); scanf("%d", &times); times = (times+1)/2; do { compare = rand()%3; printf("輸入剪刀(0), 石頭(1), 布(2)\n"); scanf("%d", &input); if(compare == input) { printf("平手\n"); } else if(compare == (1 + input)%3) { printf("輸\n"); ++lost; } else { printf("贏\n"); ++win; } } while( win<times && lost<times); if(win==times) { printf("這次你贏\n"); } else { printf("這次你輸\n"); } } -- 其實沒有要你印出對方出什麼,根本就不用比 rand出來的數字當輸贏平手 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.168.67.96 ※ 編輯: tsaiminghan 來自: 218.168.67.96 (04/03 23:47)
文章代碼(AID): #19rYamBJ (C_and_CPP)
文章代碼(AID): #19rYamBJ (C_and_CPP)