Planet Program *URGENT*

Hello

I was to write a program that calculates a person's weight on a certain planet. The user is to enter their weight, the name of the planet they wish to see their name on, and then their first and last name. I need help to finish the program.

Here is what I have so far:

 ``1234567891011121314151617181920212223242526272829`` ``````#include #include #include using namespace std; int main() { //variables string planetName[8] = {"Mercury" , "Venus" , "Earth" , "Mars" , "Jupiter" , "Saturn" ,"Uranus" , "Neptune"}; string phrase[8] = {"You way the same!" , "You've been eating too much!" , "Eating too many hamburgers I see!" , "You must be exercising alot!" , "You need to eat more!" , "Woah you're thin!" , "You need to start dieting" , "You're eating way too much!"}; string name = ""; string enteredPlanet = ""; int weight = 0; double calculations[8] = {1.00, .97, .34, 4.00, .75, .66, .07, .18}; int answer = 0; cout << "Please enter you're weight: "; cin >> weight; cout << "Enter the name of the planet you would like to see your weight on: "; getline(cin ,enteredPlanet); cout << "Enter your name: "; getline(cin, name, '\n'); system("pause"); return 0; } //end of main function ``````
Last edited on
Hi, I need to check with you. You want inputs from the user (weight, name of the planet and their name).

For the `calculations[8]`, is this the factor to multiply to the Mass for each planet respectively? For example, my mass on Earth is 50kg, so the mass on Mercury is 50kg*1.00 = 50kg?
precisely

I see. I think you will need to create 3 functions. 1) Get inputs from the user, 2) Do calculation, 3) Output the results and other information

For Example:
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364`` ``````//1) Get inputs from user: void userInput(string& PlanetName, string& UserName, double& currentMass) { cout << "Enter the name of the planet: "; cin >> PlanetName; while (PlanetName.compare("Mercury") != 0 && PlanetName.compare("Venus") != 0 && PlanetName.compare("Earth") != 0 && PlanetName.compare("Mars") != 0 && PlanetName.compare("Jupiter") != 0 && PlanetName.compare("Saturn") != 0 && PlanetName.compare("Uranus") != 0 && PlanetName.compare("Neptune") != 0 ) { cout << "Enter the name of the planet: "; cin >> PlanetName; } cout << "Enter your mass: "; cin >> currentMass; cout << "Enter your name: "; cin >> UserName; cout << "----------------------------------------" << endl; } // 2) Do the calculation: double calculateWeight(string PlanetName, double currentMass) { double newMass = 0.00; if (PlanetName == "Mercury") newMass = currentMass*1.00; if (PlanetName == "Venus") newMass = currentMass*0.97; ...... ...... return newMass; } // 3) Output the results and other information void resultOutput(string Name, string Planet, double currentMass, double newMass) { cout << "Name of the User : " << Name << endl; cout << "Planet chose : " << Planet << endl; cout << "Current Mass(kg) : " << currentMass << endl; cout << "New Mass(kg) : " << newMass << endl; } // Main Program int main() { string Name; string Planet; double currentMass = 0.00; double newMass = 0.00; userInput(Planet, Name, currentMass); newMass = calculateWeight(Planet, currentMass); resultOutput(Name, Planet, currentMass, newMass); system("pause"); return 0; }``````

 //1) Get inputs from user: void userInput(string& PlanetName, string& UserName, double& currentMass) { cout << "Enter the name of the planet: "; cin >> PlanetName; while (PlanetName.compare("Mercury") != 0 && PlanetName.compare("Venus") != 0 && PlanetName.compare("Earth") != 0 && PlanetName.compare("Mars") != 0 && PlanetName.compare("Jupiter") != 0 && PlanetName.compare("Saturn") != 0 && PlanetName.compare("Uranus") != 0 && PlanetName.compare("Neptune") != 0 ) { cout << "Enter the name of the planet: "; cin >> PlanetName; } cout << "Enter your mass: "; cin >> currentMass; cout << "Enter your name: "; cin >> UserName; cout << "----------------------------------------" << endl; } // 2) Do the calculation: double calculateWeight(string PlanetName, double currentMass) { double newMass = 0.00; if (PlanetName == "Mercury") newMass = currentMass*1.00; if (PlanetName == "Venus") newMass = currentMass*0.97; ...... ...... return newMass; } // 3) Output the results and other information void resultOutput(string Name, string Planet, double currentMass, double newMass) { cout << "Name of the User : " << Name << endl; cout << "Planet chose : " << Planet << endl; cout << "Current Mass(kg) : " << currentMass << endl; cout << "New Mass(kg) : " << newMass << endl; } // Main Program int main() { string Name; string Planet; double currentMass = 0.00; double newMass = 0.00; userInput(Planet, Name, currentMass); newMass = calculateWeight(Planet, currentMass); resultOutput(Name, Planet, currentMass, newMass); system("pause"); return 0; }
even this code wouldnt work. im not exactly sure why, but there are to many errors
This is not a complete code. For
 ``123456789101112131415`` ``````// 2) Do the calculation: double calculateWeight(string PlanetName, double currentMass) { double newMass = 0.00; if (PlanetName == "Mercury") newMass = currentMass*1.00; if (PlanetName == "Venus") newMass = currentMass*0.97; ...... ...... return newMass; }``````

you will need to fill in the rest of the planets and their respective mass factor.
In addition, you will need to include all the necessary files, for example `#include <string> `.

Hope this helps :))
Last edited on
closed account (3CXz8vqX)
Start from the top, solve it, recompile... the art of debugging ^-^

What's the first error? (Also did you actually read the code and fill in the blanks?)
Topic archived. No new replies allowed.