iT邦幫忙

0

Please tell me how to write the program. Thx

  • 分享至 

  • xImage

A common dice game named Sic Bo101utilizes three dice. And one of the gameplay options is Odd or Even, that is: A player may place wagers:
(a) “Odd”, which shall:
I. win if any of the totals 5, 7, 9, 11, 13, 15 or 17 appears in any combination of the three dice, except in the case of triple 3 or triple 5, and
II. lose if any other total appears, or if the totals 9 or 15 are determined as a result of the combination of the dice showing triple 3 or triple 5 respectively.
(b) “Even”, which shall:
I. win if any of the totals 4, 6, 8, 10, 12, 14 or 16 appears in any combination of the three dice, except in the case of triple 2 or triple 4, and
II. lose if any other total appears, or if the totals 6 or 12 are determined as a result of the combination of the dice showing triple 2 or triple 4 respectively.
Please write a program that play the game described above 1000 times with a random bet on “odd” or “even” and calculate the player’s wining
percentage.

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
4
海綿寶寶
iT邦大神 1 級 ‧ 2021-11-11 17:12:53

Or you can find answer here.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

float ranme(int seq) {
    int bet = (rand()%2);
    int dice1 = (rand()%6)+1;
    int dice2 = (rand()%6)+1;
    int dice3 = (rand()%6)+1;
    int sum = dice1+dice2+dice3;
    int winlose = 0;
    char arrEO[2][5] = {"even", "odd"};
    char arrWL[2][5] = {"Lose", "Win"};
    
    if ((dice1==dice2)&&(dice2==dice3)) {
        winlose = 0;
        //printf("%d All dices was:%d %s\n",seq, dice1, arrWL[winlose]);
    } else {
        winlose = (sum%2)==bet ? 1: 0;
        //printf("%d Bet in %s and sum was %d , %s\n", seq, arrEO[bet], sum, arrWL[winlose]);
    }
    return (float)winlose;
}

void main() {
    float N = 1000.0;
    float sum = 0.0;
    srand(time(NULL));
    for (float i=0;i<N;i+=1) {
        sum += ranme(i+1);
    }
    printf("Win %.0f from %.0f times, percentage is %.2f\n", sum, N, (sum/N)*100.0);
}

國際化的學生作業明燈.

其實完整題目有用「中文」
1.要求上傳至 Moodle
2.提供 Pseudocode
/images/emoticon/emoticon25.gif

0

I don't think anyone off of the internet can tell you how to write the program, you need someone in person to teach you. I wanted to learn the program behind this link in https://www.dashtech.org/the-importance-of-technology-in-education/. Only a professional in person was able to help me with this!

0
alethea
iT邦見習生 ‧ 2023-10-18 11:35:07

Hi there, I found your blog via Google while searching for a time card calculator and your post looks very interesting to me.

我要發表回答

立即登入回答