/* This file is the errors.c file with the compile errors fixed and also
		1. first output line limiting 1.750000 to 1.75
		2. fixing the result of the sphere volume (semantic error involving
			truncation) - couple of different ways to accomplish this (two 
			shown below)
		3. math library included
		4. PI commented out and use of M_PI instead
		5. pow() function being used in place of radius * radius * radius
		
*/

#include <stdio.h>
#include <math.h>

int main (void) {

	// variables for showing precedence and integer truncation
	int x = 4, y = 3, z = -10, result;

	// variables needed for volume of a sphere
	// const float PI = 3.141592;  // defines a constant: will not allow
	  									    // its value to be changed
	float volume = 0;    			
	int radius = 0;


	// Show precedence and integer truncation
	result = y + z / x;
	printf("\nresult of y + z / x is %d, NOT %.2f  \n", result, -1.75);

	// Get user input
	printf("\nEnter radius: ");  			
	scanf("%d", &radius);     			

	// volume of a sphere = 4/3 * PI * r * r * r
	volume = x / (float)y * M_PI * pow(radius, 3);
	// or:
	// volume = M_PI * x / y * pow(radius, 3);

	// Print sphere radius and volume
	printf("\nSphere volume = (");
	printf("%d ", x);  			 		
	printf(" / ");
	printf("%d ", y);  			 		
	printf(" * ");
	printf("%f", M_PI);  			 		
	printf(" * ");
	printf("%d ", radius);			 	 		
	printf(" * ");
	printf("%d ", radius);			 	 		
	printf(" * ");
	printf("%d ", radius);			 	 		
	printf(") = ");				 		
	printf("%.2f\n\n", volume);		

	return 0;
}



