使用 If 语句的 C++ 变量赋值

C++ Variable Assignment with If statement

我正在尝试编写一个系统,让用户可以选择是否要使用组合框输入日、月或年中的日期。这是我的代码:

    double Years;
    
    if (FinancialTermType->SelectedIndex == 0)
    {
        String ^ TermTextbox = Term->Text;
        std::wstring TermString(TermTextbox->Data());
        Years = std::stod(TermString);
    }
    else if (FinancialTermType->SelectedIndex == 1)
    {
        String ^ TermTextbox = Term->Text;
        std::wstring TermString(TermTextbox->Data());
        double month = std::stod(TermString);
        Years = (month / 12);
    }
    else if (FinancialTermType->SelectedIndex == 2)
    {
        String ^ TermTextbox = Term->Text;
        std::wstring TermString(TermTextbox->Data());
        double day = std::stod(TermString);
        Years = (day / 365);
    }

但它警告说 warning C4701: potentially uninitialized local variable 'Years' used。谢谢

Years 有一个初始值,例如定义变量时Double Years = 0