擲狀元紅游戲怎麼玩
1. 與電腦玩擲骰子游戲,游戲規則如下:每次擲三個骰子計算總點數,先由電 腦坐莊,莊家輸了換庄,一局游戲
假定題目的意思是比較兩個人骰子的大小。
1 #include <stdio.h>
2 #include <math.h>
3 int main()
4 {
5 int player_a,robot_b,win_round,lost_round,
6 round,start;
7 float winrate;
8 start=1;
9 win_round=0;
10 lost_round=0;
11 round=0;
12 while(start>0)
13 {
14 round++;
15 player_a=rand()%18+1;
16 robot_b=rand()%18+1;
17 if(player_a>robot_b)
18 win_round++;
19 else if(player_a<robot_b)
20 lost_round++;
21
22 printf("\nTotal round is %d\n",round);
23 printf("Round of win is %d\n",win_round);
24 printf("Round of lost is %d\n",lost_round);
25 printf(" Rating of winning is %.1f%\n",win_round/(round*0.01));
26 printf("****continue??****\n");
27 printf("input 0 to exit\n");
28 scanf("%d",&start);
29 }
30 }