+ 3
But a much easier way is this:
https://code.sololearn.com/cO69aIIUB3BC/?ref=app
+ 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;
}
+ 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.
+ 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;
}
+ 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;
}



