### 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;

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.

 ``1234567891011121314151617181920212223242526272829303132333435363738`` ``````// Moon Surface.cpp : main project file. #include "stdafx.h" #include #include #include #include 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.