This was my original assignment so you can understand what I was doing. Its done now and graded, but I'm just trying to improve on it for my personal knowledge of how to make it better.
#include <stdio.h> //preprocessor command to include the standard I/O header library
#include <math.h> //preprocessor command to include the math header library
int main() //identifies the main program
{
/* Declare variables */
double num1, num2, num3, sumT, prodT, avgT, sq1, sq2, sq3, sqRoot1, sqRoot2, sqRoot3;
int method;
/* Have the user Enter the 3 numbers */
printf("Enter 3 number and choose Calculation method \n\n");
printf("Enter the first number\n");
scanf ("%lf",&num1);
printf("Enter the second number\n");
scanf ("%lf",&num2);
printf("Enter the third number\n");
scanf ("%lf",&num3);
/* Ask User what to do with those numbers. */
/* 1 = Calculate the sum and average */
/* 2 = Calculate the product */
/* 3 = Calculate the square of each number */
/* 4 = Calculate the square root of each number */
printf("Enter a method to calculate the three numbers entered.\n");
printf("1 = Calculate the sum and average of the three numbers\n");
printf("2 = Calculate the product of the three numbers\n");
printf("3 = Calculate the square of each number\n");
printf("4 = Calculate the square root of each number\n");
scanf ("%i",&method);
/* Compute the values of the three numbers */
sumT=num1+num2+num3;
prodT=num1*num2*num3;
avgT=sumT / 3;
sq1=num1*num1;
sq2=num2*num2;
sq3=num3*num3;
sqRoot1=sqrt(num1);
sqRoot2=sqrt(num2);
sqRoot3=sqrt(num3);
/* Perform Operation requested by user. */
/* Report an error if any other number is entered*/
// If the value entered is 0 or > 4, program ends
if (method==0 || method>4){
printf ("Method entered does not match option 1, 2, 3, or 4\n");
goto end;
}
if (method==1){
printf("The SUM of the three values is: %5.3lf \n", sumT);
printf("The AVERAGE of the three values is: %5.3lf \n", avgT);
}
if (method==2){
printf("The PRODUCT of the three values is: %5.3lf \n", prodT);
}
if (method==3){
printf("The SQUARE of each number is: %5.3lf %5.3lf %5.3lf \n", sq1, sq2, sq3);
}
if (method==4){
printf("The SQUARE ROOT of each number is: %5.3lf %5.3lf %5.3lf \n", sqRoot1, sqRoot2, sqRoot3);
}
end:
getchar ();
getchar ();
/* Exit program */
return 0;
}