Write a C++ Program that asks the user to enter his or her weight and the name o
ID: 3540269 • Letter: W
Question
Write a C++ Program that asks the user to enter his or her weight and the name of a planet. Write the program so it uses an enumerated type to represent the planet. The following table gives the factor by which the weight must be multiplied for each planet. The program should output an error message if the user doesn't input a correct planet name. The prompt and the error message should make it clear to the user how a planet name must be entered. Be sure to use proper formatting and appropriate comments in your code. The output should be labeled clearly and formatted neatly.
Mercury 0.4155
Venus 0.8975
Earth 1.0
Moon 0.166
Mars 0.3507
Jupiter 2.5374
Saturn 1.0677
Uranus 0.8947
Neptune 1.1794
Pluto 0.0899
Explanation / Answer
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
enum Planet{Mercury,Venus,Earth,Moon,Mars,Jupiter,Saturn,Uranus,Neptune,Pluto};
Planet thisPlanet;
double weight;
string planet;
int main()
{
cout<<"Please enter the weight and name of the planet"<<endl;
cin>>weight;
cin>>planet;
checkPlanet(planet,weight);//error here
return 0;
}
void checkPlanet(Planet,weight)
{
switch(Planet)
{
case Mercury: cout<< "Weight on Mercury"+(weight*0.4155) <<endl;
break;
case Venus: cout<< "Weight on Venus"+(weight*0.8975) <<endl;
break;
case Earth: cout<< "Weight on Earth"(weight*1.0) <<endl;
break;
case Moon: cout<< "Weight on Moon"+(weight*0.0.166) <<endl;
break;
case Mars: cout<< "Weight on Mars"+(weight*0.3507) <<endl;
break;
case Jupiter: cout<<"Weight on Jupiter"+(weight*2.5374)<<endl;
break;
case Saturn: cout<< "Weight on Saturn"+(weight*1.0677)<<endl;
break;
case Uranus: cout<<"Weight on Uranus"+(weight*0.8947)<<endl;
break;
case Neptune: cout<<"Weight on Neptune"+(weight*1.1794)<<endl;
break;
case Pluto: cout<<"Weight on Pluto"+(weight*0.0899) <<endl;
break;
defualt: cout<<"The planet you entered is wrong!!!"<<endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.