2017-07-25 36 views
-7
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选择?数学程序与未初始化的本地变量选择

+6

那么,它显示“未初始化的局部变量选择”,因为它是。这很明显。 – DimChtz

+0

我假设你在'menu'中有一个'choice'变量?再次审查范围规则。这不是'main'中的变量。编译器非常适合突出显示'main'中的那个。 – StoryTeller

+1

可能重复[是未初始化的局部变量最快的随机数生成器?](https://stackoverflow.com/questions/31739792/is-uninitialized-local-variable-the-fastest-random-number-generator) –

回答

1

在将其值与其他值进行比较之前,您的代码不会初始化变量choice。你可能打算使用类似于

int choice = menu(); 
printf("You have selected the choice %d", choice);