2017-07-25 55 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);