将int传入Function,将int传入Switch,并更改int的值

时间:2017-06-29 03:12:13

标签: c++ function switch-statement return-value

int upgradeControl(int currentUpgrade) {

    // This section returns the value of an upgrade
    switch (currentUpgrade) {
        case 0: currentUpgrade = 0;
            break;
        case 1: currentUpgrade = 100;
            break;
        case 2: currentUpgrade = 300;
            break;
        case 3: currentUpgrade = 600;
            break;
        case 4: currentUpgrade = 1000;
            break;
        case 5: currentUpgrade = 1500;
            break;
        default: std::cout << "We have an error";
    }
}

我需要我的代码将一个新值返回给另一个函数,但是CLion说我的交换机中嵌套的所有内容都无法访问。

1 个答案:

答案 0 :(得分:0)

int upgradeControl(int currentUpgrade) {
    // This section returns the value of an upgrade

    switch (currentUpgrade) {
        case 0: currentUpgrade = 0;
            break;
        case 1: currentUpgrade = 100;
            break;
        case 2: currentUpgrade = 300;
            break;
        case 3: currentUpgrade = 600;
            break;
        case 4: currentUpgrade = 1000;
            break;
        case 5: currentUpgrade = 1500;
            break;
        default: std::cout << "We have an error";
    }

    return currentUpgrade;
}