I'm needing a little help, this program is meant to calculate and output the body weight of users vs their body weight on planets in our solar system.
When I try to use a switch statement for this program, the entire statement is marked as error specifically 'Illegal case error' and 'case label may only be used within a switch' errors .I have tried comparing my statement with others in my textbook but can find no difference. Please tell me how I can fix this.
#include <cctype>
#include <iostream>
#include <cmath>
using namespace std;
double weight;
double planet_weight;
string planet;
double weightonplanet = 0;
enum planet_names{Mercury,Venus,Earth,Moon,Mars,Jupiter,Saturn,Uranus,Neptune,Pluto};
int main()
{
cout << "********************************************************************" << endl;
cout << endl;
cout << "Enter the name of a planet from the following options:" << endl;
cout << "(Mercury,Venus,Earth,Moon, Mars,Jupiter,Saturn,Uranus,Neptune,Pluto)" << endl;
cout << endl;
cout << "********************************************************************" << endl;
cin >> planet;
cout << endl;
cout << endl;
cout << "Please enter your current weight (ex:205)" << endl;
cin >> weight;
cout << endl;
cout << "You have entered " << planet << "." << endl;
cout << "You currently weigh " << weight << "lbs." << endl;
cout << "Your weigh on " << planet << "is " << weightonplanet << " ." << endl;
while (true)
{
switch (string planet);
{
case Mercury:
weightonplanet = weight * 0.4155;
break;
case Venus:
weightonplanet = weight * 0.8975;
break;
case Earth:
weightonplanet = weight * 1.0;
break;
case Moon:
weightonplanet = weight * 0.166;
break;
case Mars:
weightonplanet = weight * 0.3507;
break;
case Jupiter:
weightonplanet = weight * 2.5374;
break;
case Saturn:
weightonplanet = weight * 1.0677;
break;
case Uranus:
weightonplanet = weight * 0.8947;
break;
case Neptune:
weightonplanet = weight * 1.1794;
break;
case Pluto :
weightonplanet = weight * 0.899;
break;
}
}
return weightonplanet;