具有未初始化的局部变量选择的数学程序

时间:2017-07-25 09:06:25

标签: c++ math

 void main()
{
    int choice;
    //printf("You have selected the choice %d",menu());

    if (choice == 1)
    {
        printf("You have selected addition\n");
        additionmenu();
    }
    else if (choice == 2)
    {
        printf("You have selected subtraction\n");
        subtractionmenu();
    }
    else if (choice == 3)
    {
        printf("You have selected multiplication\n");
        multiplicationmenu();
    }
    else
    {
        printf("Invalid choice\n");
    }

    system("pause");

它显示未初始化的局部变量选择,它与我声明为char选择的另一个选择有什么关系?

1 个答案:

答案 0 :(得分:1)

在将其值与其他值进行比较之前,您的代码不会初始化变量choice。你可能想要使用像

这样的东西
int choice = menu();
printf("You have selected the choice %d", choice);