// INSERT YOUR PROGRAM COMMENTS HERE
//
// Name:
// Student Number:

#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdlib>

using namespace std;

bool isInt (double value) {
    double dummy;
    return bool(modf(value, &dummy) == 0);
}

double sqr(double value) { 
	return value * value; 
}

int main (void) {

    // INSERT YOUR CONSTANT DECLARATIONS HERE
const double E = 207e9;
    // INSERT YOUR VARIABLE DECLARATIONS HERE
double d,th,inV,p,b,c,sum=0,count,greatestp=0,ave,s=0,gd,gth,ginV;   
    // INSERT YOUR STATEMENTS HERE
    
cout << "Enter diameter, tire thickness, and interference (-1 -1 -1 to stop): "<<endl;
cin >> d >> th >> inV;

while (!(d==-1&&th==-1&&inV==-1)){
	if (d < 0.5||d > 2.5||th < 0.05||th > 0.1||inV < 0||inV > 0.005*d){
		cout << "invalid value ignored." << endl;
		
	}else {
		b = d/2;
   		c = d/2 + th;
    	p = (inV/b)/((1/E)*(1 + ((c*c + b*b)/(c*c - b*b))));
    	cout << "The pressure is " << p << endl;
    
    	count = count + 1;
    	
  	if ( count == 1 || p > greatestp ) {
    	greatestp = p;
    	gd=d;gth=th;ginV=inV;
    	 }//end if
    	 
    	 sum = sum + p;	 
    	 
    }//endif	 
    
    cout << "Enter diameter, tire thickness, and interference (-1 -1 -1 to stop): "<<endl;
    cin >> d >> th >> inV;
}//end while
   	 
cout << "The average pressure is " << sum/count << endl;
cout << "The greatest pressure is " << greatestp << endl;
cout << "  diameter = " << gd << "  thickness = " << gth << "  interference = " << ginV << endl;

    



    system("PAUSE"); return 0;

}
