I am very new to programming and I need to have a way to switch between two different class names depending on a user input for a school project. Listed below was my initial thoughts but I am probably very wrong.
int main () {
cout << "Class Practice"<< endl;
int switcher;
switcher = 0;
cin >> switcher;
string which;
if (switcher = 1){
which = 'current';
}
elseif (switcher = 2){
which = 'cool';
}
Tempature which;
float intemp;
char inscale;
cout << "Input tempature: ";
cin >> intemp;
cout << "Input Scale: (F - Farhienheit, C - Celsius, K - Kalvin): ";
cin >> inscale;
which.temp = intemp;
which.scale = inscale;
I want the switch to change the name assigned to class temperature depending on the user input. So if I inputted a 1 as the value of switcher it would make line 14 "Tempature current" and make lines 23 & 24 "current.temp = intemp;" "current.scale = inscale:". If I were to input a 0 as the value of switcher it would make line 14 "Tempature cool" and make lines 23 & 24 "cool.temp = intemp;" "cool.scale = inscale;".
I want the switch to change the name assigned to class temperature depending on the user input. So if I inputted a 1 as the value of switcher it would make line 14 "Tempature current" and make lines 23 & 24 "current.temp = intemp;" "current.scale = inscale:". If I were to input a 0 as the value of switcher it would make line 14 "Tempature cool" and make lines 23 & 24 "cool.temp = intemp;" "cool.scale = inscale;".
I may be going about this completely wrong but that is my ultimate goal.
Now you could Search&Replace "which" with "current" in one function and with "cool" in the other, but why copy-paste-duplicate all that code? If you notice a typo, you must remember to fix it in every copy.