我的 RPG 的统计分配功能无法正常工作

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

当我运行代码并进入统计分配函数时,英特尔已经为其分配了一个点,而其余统计数据则没有。为什么变量 intel 在分配任何点之前就等于 1?我本以为在开始时将其初始化为 0 与所有其他变量会在调用玩家开始分配点时将其设置为 0 吗?除了英特尔之外的所有其他变量也是如此吗?

#include <stdio.h>

void startgame();
int makechar(int ref, int dex, int intel, int str);

int main(){
    int health = 100;
    int ref, dex, intel, str = 0;

    startgame();
    makechar(ref, dex, intel, str);
    return 0;
}

void startgame(){
    char decision[10];

    do{
        printf("Welcome to Grounded Python, a game by Delso Interactive. Type 'start' to continue!\n");
        fgets(decision, 10, stdin);
        decision[strcspn(decision, "n")] = '\0';

            if(strcspn(decision, "start") == 0){
                break;
            }

            else if (strcspn(decision, "quit") == 0){
                printf("quiting...");
                exit(0);
            }

    }

    while(strcspn(decision, "start") != 0);

    return 1; 
}

int makechar(int ref, int dex, int intel, int str){
    int pointpool = 10;
    int sel = 0;
    
    printf("[BOOTING DEFIB.INC BIOS]\n");
    printf("[ERROR FAILED TO LOAD USER STATISTICS.]\n[REQUESTING USER ENTER THEM MANUALLY.]\n[FAILURE TO DO SO WITHIN 7 BUISNESS DAYS WILL RESULT IN TERMINATION OF EMPLOYMENT.]\n[PLEASE CONTACT IT SUPPORT IF YOU HAVE ANY ISSUES COMPLETING THIS TASK.]");
    
    while(pointpool >= 0){
        printf("Allocate statistic points by inputing the integer that corresponds to the statistic you want to increase. You may only increase your statistics by 10 points:\n");
        printf("[1] Reflex = %d\n", ref);
        printf("[2] Dexterity = %d\n", dex);
        printf("[3] Intelligence = %d\n", intel);
        printf("[4] Strength is %d\n", str);
        
        scanf("%d", &sel);

        switch(sel){
            case 1:
                ref = ref + 1;
                pointpool = pointpool - 1;
                break;
            case 2:
                dex = dex + 1;
                pointpool = pointpool - 1;
                break;
            case 3:
                intel = intel + 1;
                pointpool = pointpool - 1;
                break;
            case 4:
                str = str + 1;
                pointpool = pointpool - 1;
                break;
        }

    }
}

当用户被要求开始输入统计数据时,我期望英特尔统计数据为零

c adventure
1个回答
0
投票

在这一行中:

int ref, dex, intel, str = 0;

str
初始化为0。 其余未初始化。
IE。它相当于:

int ref;
int dex;
int intel
int str = 0;
© www.soinside.com 2019 - 2024. All rights reserved.