C++ Switch statement

Hello all, I am seeking help with my program. The program determines how much you would weigh on another planet. When running the program, i'm not receiving results when typing the planet to receive the weight calculation.
What am I lacking?


switch (x)
{
case '0': cout << planet_name << "Your weight on (mercury) is: " << weight;
break;
case '1': cout << planet_name << "Your weight on (venus) is: " << weight;
break;
case '2': cout << planet_name << "Your weight on (earth) is: " << weight;
break;
case '3': cout << planet_name << "Your weight on the (moon) is: " << weight;
break;
case '4': cout << planet_name << "Your weight on (mars) is: " << weight;
break;
case '5': cout << planet_name << "Your weight on (jupiter) is: " << weight;
break;
case '6': cout << planet_name << "Your weight on (saturn) is: " << weight;
break;
case '7': cout << planet_name "Your weight on (uranus) is: " << weight;
break;
case '8': cout << planet_name << "Your weight on (neptune) is: " << weight;
break;
case '9': cout << planet_name << "Your weight on (pluto) is: " << weight;
break;
default: cout << "Error - invalid planet name.";
break;
}
Last edited on
Since x is integer, you should remove the apostrophes from case statements.

Ex:
1
2
3
4
5
6
7
8
9
10
11
12

switch (x)
{
    case 0: cout << planet_name << "Your weight on (mercury) is: " << weight;
    break;

    case 1: cout << planet_name << "Your weight on (venus) is: " << weight;
    break;

[....]
}
Last edited on
Thank you, that resolved my problem.
Topic archived. No new replies allowed.