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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <string>
#include <iomanip>
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// 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.