遇到开关错误:按大小写跳过了var

时间:2019-05-11 20:12:23

标签: c++ switch-statement

我正在使用开关选项制作转换器,用户可以在其中选择他们想使用的转换器,然后让他们输入信息。

问题出在'case3'中,程序给我所有'case2'中变量的错误。而且作为初学者,我不知道如何解释此错误。

这是一个简短的文件,因此我将在其中大部分不包含功能的地方发布

我试图删除'case2',在情况1中,它给变量带来了相同的错误。

int main(){     诠释选择;

cout << "--------------------------------------";
cout << "Welcome to the unit conversion program";
cout << "--------------------------------------";

cout << "Options of available units conversions:" << endl;
cout << "1. Convert temperature in Fahrenheit to Celsius" << endl;
cout << "2. Convert inches and feet to centimeters" << endl;
cout << "3. Convert miles per hour to kilmeters per hour" << endl;
cout << "0. Exit" << endl;
cout << "Choose and option: ";
cout << "Choose an option: ";
while (!(cin >> choice) || !(choice >= 0 && choice <= 3)) {
    cin.clear();
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    cout << "Invalid input. Try again: ";
}
switch (choice)
{
case 1:
    double fahr;
    double cel = ((fahr * 5.0) - (5.0 * 32)) / 9;
    cout << "Convert temperature in Fahrenheit to Celsius:";
    cout << "-------------------------------------------";
    cout << "Input the temperature in Fahrenheit to Celcius:";
    cin >> fahr;
    cout << "The temperature in Fahrenheit : " << fahr;
    cout << "The temperature in Celsius : " << cel;


    break;
case 2:
    const double feet_to_inch = 12;
    const double inch_to_centi = 2.54;
    int feet = 0;
    int inches = 0;
    double total_inches = 0.0;
    double total_centi = 0.0;
    cout << "\n\n Convert inches and feet to centimeters:\n";
    cout << "---------------------------------------------------\n";
    cout << " Input the feet number: ";
    feet = getInt();
    cout << " Input the inches number: ";
    inches = getInt();
    total_inches = feet * feet_to_inch + inches;
    total_centi = total_inches * inch_to_centi;
    cout << "/n The Result is :" << total_centi << endl;
    break;
case 3:
    double kmph = 0.0;
    double mph = 0.0;
    cout << "\n\n Convert miles per hour to kilometers per hour :\n";
    cout << "----------------------------------------------------\n";
    cout << " Input the distance in miles : ";
    mph = getDub();
    kmph = (mph / 0.6213712);
    cout << " The " << mph << " Km./hr. means " << kmph << " Miles/hr."

        << endl;

    cout << endl;
    break;
}

它不会建立。在其他情况下,所有变量的结果都是错误的。

严重性代码描述项目文件行抑制状态 错误“ C2360”初始化“ total_inches”被“ case”标签跳过 错误“ C2360”初始化“ total_centi”被“案例”标签跳过了
错误“ C2360”初始化“ inch_to_centi”被“ case”标签跳过
错误“ C2360”的“英寸”初始化被“大小写”标签跳过
'case'标签跳过了'feet_to_inch'的错误C2360初始化 错误“ C2360”的“ feet”初始化被“ case”标签跳过 错误“ C2360”初始化“ cel”被“大小写”标签跳过
错误“ C2360”初始化“ cel”被“大小写”标签跳过

0 个答案:

没有答案