Program that finds the surface area of moon.

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;


const double PI = 3.14159265;
const double RADIUS = 1738.3;

double area;
double rate;
int main ()
{

cout << fixed << setprecision( 3 );

cout << "Please enter the % of the moon's face that appears illuminated: ";
cin >> rate;

cout << endl;

area = 2 * pow( RADIUS, 2 ) * PI * ( rate / 100 );

cout << "The surface area based on your percentage is: ";
cout << area << " square kilometres." << endl;

return( 0 );
}


@kajondra

Very impressive. Can you convert that to square miles? Also, here's your program now with comma's in the numbers.

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
// Moon Surface.cpp : main project file.

#include "stdafx.h"
#include <iostream>
#include <locale>
#include <iomanip>
#include <cmath>

using namespace std;

const double PI = 3.14159265;
const double RADIUS = 1738.3;

int main ()
{
	double area;
	double rate;

	#ifdef _WIN32
		locale loc("English_America");
	#else
		locale loc("en_US.UTF8");
	#endif
     cout.imbue(loc); // or use your ofstream object
 
	cout << "Please enter the % of the moon's face that appears illuminated: ";
	cin >> rate;

	cout << endl;

	area = 2 * pow( RADIUS, 2 ) * PI * ( rate / 100 );

	cout << "The " << rate << "% illuminated area of the total moon surface is" << endl;
	cout << fixed << setprecision( 3 );
	 cout << "equal to " << fixed << area << " square kilometres." << endl << endl << endl;

	return( 0 );
}
Topic archived. No new replies allowed.