# Thread: Homework Porblem

1. ## Homework Porblem

I am a beginner in C++ and am currently taking the class online. I have a problem that I do not know where to begin on.

Ok here is the problem...Write a C++ program that allows users to enter the percentage of the moons face that appears illuminated, and that outputss the surface area of that portion of the moon. The formula for the surface area of a segment of a sphere is

S= 2 * (radius * radius) * angle of wedge in radians

There are two radians in a circle, so the hemisphere of the moon that we see accounts for at most 3.1415927 radians. Thus if the user enters 100% (full moon) the angle of wedge is 3.1415927=

S= 2 * (1738.3 * 1738.3) * 3.1415927= 18985818.672 square kilometers

If the user enters 50%(first or first quarter) then the angle of the wedge is 3.415927 * 0.5 and so on. Be sure to use proper formating and appropriate comments in your code. Provide appropriate prompts to the user. The output should be labeled clearly and formatted neatly ( limit the decimal precision to three places as in the example above.

2. Code:
```{
int x;
double angofwed = 3.1415927, rad = 1738.3, surface;

cout << "Enter percentage: ";       // prompt
cin >> x;                                        // input

x = x / 10;

surface = 2 * (rad * rad) * (angofwed * x); // works out the surface

cout << "\n---\n SURFACE: " << surface << " square kilometers"; // displays answer
}```
Something like that I guess... But I got no idea how you would do it to 3dp, google maybe?

3. you don't have to actually have the number really be 3 decimal points, just multiply first, and adjust the output. here's what you should do

-first, multiply the surface area of the moon by 100, getting everything in front of the decimal point

-then, calculate the percentage, by multiplying the input by 0.01. like, the user types in 50, multplying by 0.01 produces 0.5

-multiply the result with the surface area. now you've got the number you want, the decimal number just isn't in place

-convert the integer to a string, or better yet, an array of chars, and output all except the last 3, then output a dot, then output the last 3.

but oh, how do we convert an integer into a char array, you ask? one simple command that's in the default libraries: itoa(). check out the msdn entry

and uh, when it comes to everything else, uh, i think stickygoo pretty much has it right

4. Originally Posted by jwmonroe
I am ... currently taking the class online...Please help me.
I refer you to cprogramming's homework policy; we are not in the habit of handing out solutions, although you seemed to have struck lucky to some extent with StickyGoo's post.

Post your own attempt at the code and describe any problems you have encountered.

5. > and that outputss the surface area of that portion of the moon
I thought the phases of the moon were defined by crescents
http://mathworld.wolfram.com/Lune.html

not segments
http://mathworld.wolfram.com/CircularSegment.html

Better make sure you're answering the right question.

6. sorry ken, havn't read that policy :S

I'll remember for next time though.

7. Are you in the RODP class? I'm taking the RODP class through Columbia State, and have done that same program. I won't give you my code, but if you still need help with the problem, or anything else later in the class, feel free to e-mail me. wave.of.atla AT gmail DOT com

8. I'm sorry I didn't know there was a no homework policy, but I really do thank you guys for the help.

9. Yes, I am still in the class. I don't have much more left though. Thank you for the offer for your help, I may need it in the future. This class has been pretty tough for me.

Popular pages Recent additions