需要有一个工作菜单,但它无法运行

问题描述 投票:0回答:1

我之前有一个与该项目类似的代码,之前已经运行过。但是,现在我无法让它运行。

Yahtzee.c

#include“Yahtzee.h”

int main(无效) {
输入= 0;

do
{
input = option_choice(options());
}

while (input != 3);

return 0; 

}

函数.c

#include“Yahtzee.h”

int 选项(无效) { int 选项 = 0;

do
{
printf("Main Menu:\n\n"

"1. Display Rules\n"

"2. Playing Games\n"

"3. Exit\n"

"Input your choose to continue: ");

scanf("%d", &options);
}

while (options < 1 || options > 3);

return options;

}

int option_choice(void) { 输入= 0;

switch (input)
{
    case 1:
    {
    printf("\nThe scorecard used for Yahtzee is composed of two sections.\n");
    printf("A upper section and a lower section.\n");
    printf("A total of thirteen boxes or thirteen scoring combinations are divided amongst the sections.\n");
    printf("The upper section consists of boxes that are scored by summing the value of the dice matching the faces of the box.\n");
    printf("If a player rolls four 3's, then the score placed in the 3's box is the sum of the dice which is 12.\n");
    printf("Once a player has chosen to score a box, it may not be changed and the combination is no longer in play for future rounds.\n");
    printf("If the sum of the scores in the upper section is greater than or equal to 63, then 35 more points are added to the players overall score as a bonus.\n");
    printf("The lower section contains a number of poker like combinations.\n");
    printf("Three of a kind: Three dice with the same face. Sum of all face values on the 5 dice.\n");
    printf("Four of a kind: Four dice with the same face. Sum of all face values on the 5 dice.\n");
    printf("Full house: One pair and a three of a kind. 25 points.\n");
    printf("Small straight: A sequence of four dice. 30 points.\n");
    printf("Large straight: A sequence of five dice. 40 points.\n");
    printf("Yahtzee!!!(five of a kind): Five dice with the same face. 50 points.\n");
    printf("Chance: May be used for any sequence of dice; this is the catch all combination. Sum of all face values on the 5 dice.\n\n");
    break;
    }

    case 2: //Play the game and the mechanics of the game.
    {
    break;
    }

    case 3:
    {       
    printf("Exit Game\n\n");
    break;
    }
}
return input;
}
c
1个回答
0
投票

您应该将函数定义更改为

int option_choice(int input)

并删除

int input = 0

问题出在这一行

input = option_choice(options());
因为
option_choice()
接受
void
但 options() 传递一个整数 行
int input = 0
也会导致问题,因为 switch-case 不考虑 case 0

© www.soinside.com 2019 - 2024. All rights reserved.