//Alexander Barks
//Feburary 3, 2023
//Lab Section 1
//Lab 2
//This program demonstrates operator precedence, integer truncation, and returns the volume of a sphere when given a radius.



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

int main (void) {

	// variables for showing precedence and integer truncation
	
	//Added a comma before y to allow code to detect it as a variable separate from x.
	int x = 4.0, y = 3.0, 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
	//Changed the colon to a semi-colon after the "volume = 0" variable.
	float volume = 0;    			
	int radius = 0;


	// Show precedence and integer truncation
	result = y + z / x;
	
	//Added missing terminating '' character and changed the apostrophe after the closing \n to be an ''. Put the closing semi-colon after the closing parentahses
	printf("\nresult of y + z / x is %d, NOT %.2f  \n", result, -1.75);


	// Get user input
	// Added opening parenthases.
	printf("Enter radius: ");  			
	//Added terminating '' , &radius);     			
	scanf("%d", &radius);
	// volume of a sphere = 4/3 * PI * r * r * r
	// Changed the variables "r" to "radius" in the equation. Also added float division operand to not truncate the division portion of the formula.
	volume = (float)x/y * M_PI * pow(radius,3) ;

	// Print sphere radius and volume
	// Removed an additional parenthases
	printf("\nSphere volume = ");
	//Changed print to printf. Added a comma before the variable.
	printf("%i ", x);  			 		
	printf(" / ");
	//Changed print to printf, added a comma before the variable.
	printf("%i ", y);  			 		
	printf(" * ");
	//Changed print to printf, added a comma before the variable.
	printf("%f", M_PI);  			 		
	printf(" * ");
	//Added format argument.
	printf("%i", radius);			 	 		
	printf(" * ");
	//Added format argument
	printf("%i", radius);			 	 		
	printf(" * ");
	//Added format argument.
	printf("%i", radius);
	//Changed period to semi-colon.	
	printf(" = ");	
	//Changed apostraphe to quotation.	
	printf("%.2f\n", volume);		

	return 0;
}



