I need some help with an assignment ASAP

Here is the prompt for the question that I need to answer. I am getting several error messages that will not allow me to compile. Any help would be appreciated. Thanks

"Write a program that prompts the user to enter the weight of a person in pounds and outputs the equivalent weight in kilogram and solar masses (used to measure the mass of stars and galaxies).

Output the both weight in pounds and kilograms rounded to three decimal places (trailing zeros if necessary). Output the weight in solar masses in scientific notation with 4 significant digits (for example, 1002 would be output as 1.0020e+003 in C++ scientific notation, which is short for 1.0020 × 10003). The relationship between pounds and kilograms and the relationship between kilograms and solar masses should declared in your program as constants. Use these constants in the conversion formulas."


Put the code you need help with here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# include <iostream>
	
	using namespace std;
	int main()
	{
	 double weight;
	 double const  weightPound;
	 double const weightSolar;
	 cout<<"Enter the weight in pounds: "<<endl;
	 cin>>weight;
	 weightPound=(weight* 0.453592);
	 weightSolar=(weight*5.0279e-31)
	 cout<<"The weight in kilograms is:"<<setprecision(3)<<fixed<<weight<<endl;
	 cout<<"The weight in pounds is:"<<setprecision(3)<<weightPound<<endl;
	 cout<<"the weight in solar masses is: "<<setprecision(4)<<scientific<<weightSolar<<endl;
	 return 0;
	}
Last edited on
Please use code tags. http://www.cplusplus.com/articles/jEywvCM9/
You can edit your post, highlight your code and click the <> button on the right.

These are declared as const, meaning you can't assign a value to it, after you've declared/defined it.
1
2
double const weightPound;
double const weightSolar;


You probably want to do something like this:
1
2
double const lb_to_kg = 0.453592;
double const lb_to_solar = 5.0279e-31;

Then you can do this
1
2
3
4
5
6
double weightKg = 0.0;   // initialise variables
// user input for weight
// etc...
weightKg = weight * lb_to_kg;
cout << "The weight in pounds is:" << setprecision(3) << fixed << weight << endl;
cout << "The weight in kilograms is:" << setprecision(3) << weightKg << endl;

weight is in pounds, not in kilograms.
OK now I am getting an error message saying, use of undeclared identifier setprecision
setprecision is part of the iomanip header.
ok, everything is good, I just need the output for the solar mass to have 4 significant digits.
Topic archived. No new replies allowed.