I'm trying to brush up on some simple C++ programs, and this one has some errors and I'm not understanding why. I'll write the errors in the comments above the line
int main(void)
{
bool x = true;
char userInput;
double weight;
string planetName;
while (x == true)
{
//endl; has the error "expected a ;"
cout << "Please enter your weight:" endl;
cin >> weight;
cout << "Please enter a planet name (The moon and pluto count)" endl;
cin >> planetName;
for (int i = 0; i < planetName[i] != '\0'; i++)
{
planetName[i] = tolower(planetName[i]);
}
//planetName has the error "expression must have integral or enum types"
switch (planetName)
{
//mercury has the error "too many characters in character constant"
case 'mercury' :
cout << "Your weight is :" << weight * .4155;
case 'venus' :
cout << "Your weight is :" << weight * .8975;
case 'earth' :
cout << "Your weight is :" << weight * 1;
case 'mars' :
cout << "Your weight is :" << weight * .3507;
case 'jupiter' :
cout << "Your weight is :" << weight * 2.5374;
case 'saturn' :
cout << "Your weight is :" << weight * 1.0677;
case 'uranus' :
cout << "Your weight is :" << weight * .8947;
case 'neptune' :
cout << "Your weight is :" << weight * 1.1794;
case 'pluto' :
cout << "Your weight is :" << weight * .0899;
case 'moon' :
cout << "Your weight is :" << weight * .116;
}
cout << "Try again?" << endl;
cout << "Press Y to see your weight on a different planet,or N to exit." << endl;
cin >> userInput;
// both == signs have "operand types are incompatable"
if (userInput == "y" || userInput == "Y")
{
break;
}
else if (userInput == "n" || userInput == "N")
{
x = false;
}
}
PressEnterToContinue();
return 0;
}
If I'm doing something in a less than intelligent way, or you think of a more intelligent way to do any of this, please feel free to say so. I don't really like using while loops, but sometimes I just can't think of anything else quickly for short programs like this.
C
?std::map< std::string, double >
to map planet names to gravitational ratios.