[Solved] Redefine this C++ variable [closed]


You cannot redefine variable, that’s simply not possible in C++.

Good news is, you don’t need to. As the name “variable” suggests, you can change it:

#include <iostream>
using namespace std;

int main() {
    string b1 = "undefined";
    cout << "Schedule\n";
    string p1;
    cin >> p1;
    if (p1 == "1") {
        b1 = "ELA"; //don't redeclare, reassign
    } else if (p1 == "7/8") {
        b1 = "SCIENCE";
    } else {
        b1 = "404/undefined\n";
    }

    cout << "Results:\n\n";
    cout << b1;
}

0

solved Redefine this C++ variable [closed]