+ 3
28th May 2018, 2:03 PM
XiLef
+ 3
You can use an Enum for that: #include <iostream> using namespace std; enum Planets { mercury, venus, earth, mars }; int main () { Planets planet = mercury; if(planet == mercury) { cout << " true"; } return 0; }
27th May 2018, 5:57 PM
XiLef
+ 1
An enum is nummerated, so you must input 0 for marcury 1 for venus 2 for earth... if you want to Input the whole word you can use a String or make a case statement to convert string to the enum.
28th May 2018, 1:23 PM
XiLef
+ 1
Your input has to be stored in a variable: #include <iostream> using namespace std; enum Planets { mercury, venus, earth, mars }; int main () { Planets planet; cin >> planet; //Write 0 in Input box if(planet == mercury) { cout << "your Input was mercury"; } return 0; }
28th May 2018, 1:45 PM
XiLef
+ 1
Sorry, i overlook, that you cant input an enum. so it should work: #include <iostream> using namespace std; enum Planets { mercury, venus, earth, mars }; int main() { int input; Planets planet; cin >> input; switch(input) { case 0: planet = mercury; break; case 1: planet = venus; break; case 2: planet = earth; break; case 3: planet = mars; break; } if (planet == mercury) { cout << "Planet is mercury!"; } return 0; }
28th May 2018, 1:59 PM
XiLef