So I'm trying to make a program that asks a user for a planet, this is stored as a string. I want to use a switch statement to make decisions (like if it's earth do this, if it's mars do this). I am aware that switch statements only take ints, so I took the string and translated it to its hex value. The issue I'm stuck on is how do I have the hex value saved as an int.
I am aware that it would be way easier to do a bunch of nested if statements, but I find that really ugly and bulky.
Here is what I have so far:
/*
* Have user input their weight and a planet
* then output how heavy they would be on that planet
* if planet is wrong
* output it
*/
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
string returnanswer(string x) {
string dat = x;
int test;
ostringstream os;
for (int i = 0; i < dat.length(); i++)
os << hex << uppercase << (int) dat[i];
string hexdat = os.str();
cout << "Text: " << dat << endl;;
cout << "Hex: " << hexdat << endl;
return hexdat;
}
int main() {
int weight;
string planet;
cout << "Please enter your weight: " << endl;
cin >> weight;
cout << "Please enter Planet" << endl;
cin >> planet;
returnanswer(planet);
return 0;
}