Code error

Hey, I need a little help. I had the program working until I used the switch statement and tried to put in a menu and now I have three errors. Could someone please take a look and tell me what I messed up? thank you





//This program determines your weight on other planets, how long it will take you to get there.
#include <iostream>
#include <string>
#include <iomanip>

void showMenu();
using namespace std;
int main()
{
// This line declares weight as a float also, planet and name as string. Declares mph as integer.
char name [256];
float weight;
int choice ;
long int MPH;

// These lines tell the program mass on other planets compared to earth
const double MERCURY = 0.27;
const double VENUS = 0.086;
const double EARTH = 1.0;
const double MARS = 0.37;
const double JUPITER = 2.64;
const double SATURN = 1.17;
const double URANUS = 0.092;
const double NEPTUNE = 1.44;

// These lines tell the program how far the planets are from the sun
const double mercuryD = 36000000;
const double venusD = 67000000;
const double earthD = 93000000;
const double marsD = 141000000;
const double jupiterD =483000000;
const double saturnD = 886000000;
const double uranusD = 1782000000;
const double neptuneD = 2793000000;

const int Mercury_choice = 1,
Venus_choice = 2,
Earth_choice = 3,
Mars_choice = 4,
Jupiter_choice = 5,
Saturn_choice = 6,
Uranus_choice = 7,
Neptune_choice = 8,
Quit_choice = 9;





// asks user to enter his/her name
cout <<"This program will tell you what your weight is on other planets and how long it will take to get there. lets start by telling me your name to begin" <<endl;
cin.getline(name,256);

//asks user to enter his/her weight
cout<< "Ok "<<name<< " Now please tell me your weight." <<endl;
cin >> weight;
// asks user to enter the speed they wish to travel.
cout << "Tell me how fast you want to travel in mph?" <<endl;
cin >> MPH;


do
{
showMenu();
cin >> choice;





// uses if and if else statement to determine what to do if one is picked. multiplies users weight by the planets mass compared with earths
//Divides planets distance by the speed they want to travel and equals how long in hours it will take.
switch (choice)
{


case '1':
cout << name << " your weight on Mercury is " <<weight*MERCURY<<" pounds. It will take you "<<mercuryD/MPH<<" hours." <<endl;
break;
case '2':
cout << name << " your weight on Venus is "<<weight*VENUS <<" pounds. It will take you "<<venusD/MPH<<" hours." <<endl;
break;
case '3':
cout << name << " your weight on Earth is " <<weight*EARTH <<" pounds. It will take you "<<earthD/MPH<<" hours."<<endl;
break;
case '4':
cout << name << " your weight on Mars is "<<weight*MARS<<" pounds. It will take you "<<marsD/MPH<<" hours."<<endl;
break;
case '5':
cout << name << " your weight on Jupiter is "<<weight*JUPITER<<" pounds. It will take you "<<jupiterD/MPH<<" hours."<<endl;
break;
case '6':
cout << name << " your weight on Saturn is "<<weight*SATURN<<" pounds. It will take you "<<saturnD/MPH<<" hours."<< endl;
break;
case '7':
cout << name << " your weight on Uranus is "<<weight*URANUS<<" pounds. It will take you "<<uranusD/MPH<<" hours."<<endl;
break;
case '8':
cout << name << " your weight on Neptune is "<<weight*NEPTUNE<<" pounds. It will take you "<<neptuneD/MPH<<" hours."<<endl;
break;



}}


return 0;
}

void showMenu()
{



cout << "1) Mercury\n"
<< "2) Venus\n"
<< "3) Earth\n"
<< "4) Mars\n"
<< "5) Jupiter\n"
<< "6) Saturn\n"
<< "7) Uranus\n"
<< "8) Neptune\n"
<< "9) QUIT\n"
<< "Enter your choice:";
}
choice is defined as an int, so in the switch statements it should be case 1: not case '1': - the single quotes would be used if the value tested were a char type.

You're missing the while part of your do/while loop.
Topic archived. No new replies allowed.