I have no clue were to begin this code

Jun 2, 2016 at 9:03pm
closed account (D4NbpfjN)
Your weight is actually the amount of gravitational force exerted on you by the earth. Moons gravity is one sixth (0.167) that of the earth gravity. Write a program that asks the user to enter his/her weight on the earth and display the corresponding weight on the moon.

i need help with this code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>
using namespace std;
int main()
{

	cout << "Please enter what your weight would be on earth.";
	cin >> weight;

	cout<<"Your weight on the moon is "











	return 0;
}
Last edited on Jun 2, 2016 at 9:08pm
Jun 2, 2016 at 9:08pm
Get input number from user
Multiply number by 0.167
Output the new number
Jun 2, 2016 at 9:08pm
The biggest part of that program is the input and output. Somewhere in the middle you need to take a number and divide it by 6, that's the easy part.
Jun 2, 2016 at 9:18pm
closed account (D4NbpfjN)
What am I missing?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream>
using namespace std;
int main()
{
	int weight;

	cout << "Please enter what your weight would be on earth.";
	cin >> weight;

	weight * 0.167;

	cout << "Your weight on the moon is \n: ";
		
		return 0;
}
Jun 2, 2016 at 9:27pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream>
using namespace std;
int main()
{
	int weight;

	cout << "Please enter what your weight would be on earth.";
	cin >> weight;

	

	cout << "Your weight on the moon is \n:"<< (weight * 0.167); // This 
		
		return 0;
}
Jun 2, 2016 at 9:29pm
You need need to output that new weight to the screen. So either output directly 'weight * 0.167' or store this new weight in a variable and output that variable.

1
2
3
4
5
6
double NewWeight = weight * 0.167;
cout << "Your weight on the moon is : " << NewWeight;

/* Or you can do the following:
cout << "Your weight on the moon is : " << weight * 0.167
*/
Last edited on Jun 2, 2016 at 9:53pm
Jun 2, 2016 at 9:33pm
You may want to use type double rather than int for the variables. The two samples above would give differing output because of that.
Jun 2, 2016 at 9:53pm
@Chervil: Woops! silly mistake. Fixed. Thanks.
Topic archived. No new replies allowed.