///////
//
// Student: Russell Lowke
//     T.F: Francis Crick
// Unit Three, Easy Supplementary - question 10 [worth 2pts],  7/7/2002
//
//  Write a C++ program that asks for the radius of a planet in meters,
//  then prints out its circumference at the equator in meters, its surface area
//  in square meters, and its volume in cubic meters.  Each output should have
//  three digits after the decimal point.


#include <iostream>
#include <iomanip>
#include <cmath>

// there dosn't seem to be a <cvalues> file, so I'm using values.h
// to get the value of PI ( M_PI ), and the Maximum integer ( MAXINT )
#include <values.h>


//
//  reads an integer from the keyboard,
//  uses error checking to ensure value is between minValue and maxValue
//
int getInt(char askStr[], int minValue, int maxValue)
{
	int mVar;
	bool inputOK = false;
	
	while (! inputOK) { 
	
		cout << askStr;						// ask query
		cin >> mVar;						// get input
		
		if ( mVar >= minValue && mVar <= maxValue )
			inputOK = true;					// input OK, exit loop
		else {
			cout << "Bad input: please enter a value between "
			     << minValue << " and " << maxValue << endl;
			cin.clear();					// clear error
			cin.ignore(80, '\n');			// empty buffer
		}
	}
	
	return mVar;
}

//
//  set cout to display up to [percision] decimal places
//
void setDecPlace(int percision)
{
	// "formula" for precision notation
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(percision);
}


void main()
{
	int planetRadius;
	
	planetRadius = getInt("Radius of planet in meters:", 0, MAXINT);

	setDecPlace(3);					// set precision to 3 dec places
	
	cout << setw(16) << "Circumference: " 
	     << (2 * M_PI * planetRadius) 
	     << " meters" << endl;
	     
	cout << setw(16) << "Surface Area: "
	     << (4 * M_PI * (planetRadius * planetRadius) )
	     << " meters squared" << endl;
	     
	cout << setw(16) << "Volume: "
		 << (1.333333 * M_PI * (planetRadius * planetRadius * planetRadius) )
		 << " meters cubed"   << endl;
}
