/****************************************************/
/****************************************************/
/*												    */
/* Title - Circle Calculator					    */
/*												    */
/* File Name - circle.cpp						    */
/*												    */
/* Author - Mark Walsh							    */
/*												    */
/* Date Written - 12/10/2003					    */
/*												    */
/* Compiler - Visual C++ 6: Should be compatible    */
/*			  with most compilers.				    */
/*												    */
/* Platform - DOS EXEcutable					    */
/*												    */ 
/****************************************************/
/*												    */
/* Description -								    */
/*												    */
/* Program to calculate the circumference, area and */
/* radius of a circle based on the user inputting a */
/* correct number.									*/
/* The program will loop until the user enters a    */
/* correct number or enters a number that allows    */
/* him/her/it to quit.								*/
/* The user is informed what the correct paramters  */
/* are when the program starts up.					*/	
/****************************************************/


/* include relevant header files */
#include <iostream> // cin, cout etc

using namespace std;		// use namepace for the stdlib for ease.

/** declare main **/
int main()
{
	/* declare variables at the start - floats and doubles are used as decimals are expected */
	float radius;
	int correctNum;					// used to check user input is correct
	const double pi = 3.14159;		// Declare 'pi' as constant as we dont want value to change
	float diameter; 
	float circumference;
	float area;	

	
	/* Prompt user for relevant input */
	cout << "Please input a valid circle diameter. \n" 
		 <<	"These are in the range 1.75 - 13.25. \n"         
		 <<	"Or a negative number to quit out. " << endl;
		 	
	/* program automaticall enters this section of code */
	do	// Enter do - loop until user chooses to exit or enters correct number.
	{
		cout << "Please input a valid number and then press return. \n";	// propmt user for valid input

		cin >> diameter;	// get users input

		if ((diameter >= 1.75) && (diameter <= 13.25))
		{
			correctNum = 0;	// if correct numbers entered make correctNum = 0
		}
		else if(diameter < 0)
		{
			cout << "You have choosen to exit. \n\n";	// inform user they have choosen to exit.
			correctNum = 1; // if numbers entered for exit selection make correctNum = 1
		}		
		else
		{
			correctNum = 2; // else correctNum = 2, trapping them in loop.
		}
	} while (correctNum == 2);

	
	
	/* If the user entered the correct number to perform the calculations enter, 
	   if he chose to exit (by entering negative number) then skip and go to end of program */
	if (correctNum == 0)
	{
		/* perform the calculations */
		radius = diameter / 2;
		area = (pi*radius)*radius;
		circumference = pi * diameter;

		/* print out the calculation results */	
		cout << "The diameter of your circle is: \t\t" << diameter << "\n";
		cout << "The radius of your circle is: \t\t\t" << radius << "\n";
		cout << "The area of your circle is: \t\t\t" << area << "\n";
		cout << "The circumference of your circle is: \t\t" << circumference << "\n\n";

	}


	return	0;	// end program

}

