I have no clue were to begin this code

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
Get input number from user
Multiply number by 0.167
Output the new number
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.
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;
}
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;
}
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
You may want to use type double rather than int for the variables. The two samples above would give differing output because of that.
@Chervil: Woops! silly mistake. Fixed. Thanks.
Topic archived. No new replies allowed.