在某些条件下使用do循环

时间:2018-04-11 01:17:37

标签: c

所以我在我的C课中制作了一个Craps游戏,并且遇到了一个问题。 如果用户掷出被认为是点的4,5,6,8,9或10。如果用户在滚动一个点之后滚动7,则会丢失。我的问题是如果用户滚动一个点,然后他们再次滚动,总和等于他们获胜的点数。如果他们在他们的点之后滚动7,我的程序可以工作,但如果他们再次滚动他们的点的总和则不行。 对不起,我知道这个问题令人困惑。

        case 1: printf("Enter your name here: ");
            scanf("%s", name);

            for(j = 0; j < i; j++){
                if(strcmp(name, pl[j].players)==0){
                    set = 1;

                    printf("* * * * * * * * * *\n");
                    printf("Press ENTER to roll the dice");
                    getchar();
                    getchar();

                    dice = (rand()%(6-1+1)+1);
                    dice1 = (rand()%(6-1+1)+1);
                    sum = dice + dice1;

                    printf("\nThe values of the dice are %d and %d whose sum is %d\n", dice, dice1, sum);

                    if(sum == 7 || sum == 11)
                    {
                        win++;
                        pl[j].wincount = win;
                        pl[j].balance = pl[j].balance + 10;
                        printf("\nYou win the game. \nYour balance is now: %d\n", pl[j].balance);
                        break;
                    }

                    else if((sum == 2) || (sum == 3) || (sum == 12))
                    {
                        lose++;
                        pl[j].balance = pl[j].balance-1;
                        printf("You lose :(\nYou balance is now: %d\n", pl[j].balance);

                        dice = (rand()%(6-1+1)+1);
                        dice1 = (rand()%(6-1+1)+1);
                        sum = dice + dice1;
                        break;
                    }

                    else
                    {
                        do
                        {
                            printf("\nYou rolled a 'point' you must now roll again.\n");
                            printf("* * * * * * * * * *\n");
                            printf("Press ENTER to roll the dice again");
                            getchar();
                            getchar();

                            dice = (rand() % (6 - 1 + 1) + 1);
                            dice1 = (rand() % (6 - 1 + 1) + 1);
                            sum = dice + dice1;
                            printf("\nThe values of the dices are %d and %d whose sum is %d\n", dice, dice1, sum);

                        }while((sum != 7) && (sum != point));

                        if(sum == 7)
                        {
                            lose++;
                            pl[j].balance = pl[j].balance - 1;
                            printf("You lose :(\nYou balance is now: %d\n", pl[j].balance);
                        }


                        else if(sum == point)
                        {
                            win++;
                            pl[j].wincount = win;
                            pl[j].balance = pl[j].balance + 10;
                            printf("\nYou won the game, you rolled your point \nYour balance is now: %d\n", pl[j].balance);
                        }
                    }
                }
            }

0 个答案:

没有答案