hey ya'll i've made this code (simple, bc that's what i am) and i think it would work except for the tiny problem that i always get the error that the switch statement is illegal, but i don't know what to put instead (when i do run the program, it stops and says that it can't run anymore b/c the statement isn't defined). any helps would be great, thankies..here's the code....

#include <iostream>
#include <cmath>
using namespace std;


int main ()
{
float inWeight;
float inPlanet;
int planet;



cout << "Enter you weight.\n";
cin >> inWeight;


cout << "Press 1 for Mercury\n";
cout << "2 for Venus\n";
cout << "3 for Earth\n";
cout << "4 for Moon\n";
cout << "5 for Mars\n";
cout << "6 for Jupiter\n";
cout << "7 for Saturn\n";
cout << "8 for Uranus\n";
cout << "9 for Neptune\n";
cout << "10 for Pluto\n";
cin >> inPlanet;


switch (planet)
{
case 1: cout << (inWeight * 0.4155);
break;
case 2: cout << (inWeight * 0.8975);
break;
case 3: cout << (inWeight * 1.0);
break;
case 4: cout << (inWeight * 0.166);
break;
case 5: cout << (inWeight * 0.3507);
break;
case 6: cout << (inWeight * 2.5374);
break;
case 7: cout << (inWeight * 1.0677);
break;
case 8: cout << (inWeight * 0.8947);
break;
case 9: cout << (inWeight * 1.1794);
break;
case 10: cout << (inWeight * 0.0899);
break;
default : cout << "Not a planet.";
}
return 0;


}

My guess is that it has something to do with this confusion:

float inPlanet;
	int planet;

	cin >> inPlanet;

	switch (planet)

rite, but i don't know how to fix it, regardless of the int

Well which do you want? planet is an uninitialized variable, so your results will be undefined. And inPlanet is actually obtained from user input, but it is not used, and cannot be used in the switch. Given that, I might try:

cin >> planet;

switch (planet)

didn't work, but that's ok
thanks anywho

didn't work, but that's ok
thanks anywho

::shakes head::

#include <iostream>
using namespace std;

int main ()
{
   float weight;
   int planet;

   cout << "Enter you weight.\n";
   cin  >> weight;

   cout << "Press 1 for Mercury\n";
   cout << "2 for Venus\n";
   cout << "3 for Earth\n";
   cout << "4 for Moon\n";
   cout << "5 for Mars\n";
   cout << "6 for Jupiter\n";
   cout << "7 for Saturn\n";
   cout << "8 for Uranus\n";
   cout << "9 for Neptune\n";
   cout << "10 for Pluto\n";
   cin  >> planet;

   switch ( planet )
   {
   case  1: cout << (weight * 0.4155);  break;
   case  2: cout << (weight * 0.8975);  break;
   case  3: cout << (weight * 1.0);     break;
   case  4: cout << (weight * 0.166);   break;
   case  5: cout << (weight * 0.3507);  break;
   case  6: cout << (weight * 2.5374);  break;
   case  7: cout << (weight * 1.0677);  break;
   case  8: cout << (weight * 0.8947);  break;
   case  9: cout << (weight * 1.1794);  break;
   case 10: cout << (weight * 0.0899);  break;
   default: cout << "Not a planet.";
   }
   return 0;

}

/* my output
Enter you weight.
150
Press 1 for Mercury
2 for Venus
3 for Earth
4 for Moon
5 for Mars
6 for Jupiter
7 for Saturn
8 for Uranus
9 for Neptune
10 for Pluto
6
380.61
*/

Swithc works with integral types, so inPlanet (float) will not work. Instead, try this

cin >> planet;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.