/********************************************/
/*              */
/* September 30, 2013.                      */
/* Filename: assignment1.GNG1106   */
/* This program performs various operations */
/* for shapes whose parameters are input    */
/********************************************/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define PI 3.141593

int main() //main program
{
    float rad, diam, area, circum, perim, side_a, side_b, height, volume;     //Float and integer declarations. Multiple variables with descriptive names were
    int select_main, select_rect, select_circ, select_cylndr, select_sphere;  //used for readability, as opposed to using one or two variables for the calculations.

    select_main = 0;

    printf("Welcome! This program helps you learn more about rectangles, circles, cylinders and spheres:"  //Welcome screen
            "by providing descriptions and calculating parameters such as circumference, area, and volume.\n\n");



        while(select_main<1 || select_main>5) //Loops while select_main value is anything other than 1,2,3,4 or 5. This allows the user to make indefinite shape selections,
        {                                      //and avoids ending the program when an erroneous number is selected.

            printf("Please enter the number corresponding to the shape you would like to investigate or press 5 to terminate program:\n"
                               "\n\t1.Rectangle\n\t2.Circle\n\t3.Cylinder\n\t4.Sphere\n\n\t5.Done\n\nYour selection is: ");
            scanf("%d", &select_main);

            switch(select_main)               //Shape selection, cases 1 through 4 each relating to a shape, with 5 ending the program. The arithmetic operations are also performed in each case.
            {
                case(1):  //Rectangle
                    {
                    select_rect = 0;
                    system("cls");  //This command clears the screen. Unfortunately it appears to be unique to Windows. For POSIX use "system(clear);"
                    printf("You have selected the Rectangle. A rectangle is a polygon with four sides, and four right angles."
                           "A rectangle with four sides of equal length is a square. Please input sidelengths a and b, followed "
                           "by the number corresponding to the operation you would like to perform.\n\n");
                    printf("a = ");
                    scanf("%f", &side_a);
                    printf("\nb = ");
                    scanf("%f", &side_b);
                    printf("\n1.Perimiter\n2.Area\n\nYour selection is: ");

                        while(select_rect<1 || select_rect>2)   //Loops while select_rect value is anything other than 1,2. Avoids complications when erroneous integers are entered
                        {
                            scanf("%d", &select_rect);          //Reads case selection. 1 for perimeter, 2 for area.

                            switch(select_rect)
                            {
                                case(1):
                                {
                                    perim = 2*(side_a+side_b);
                                    printf("\nThe perimeter of a rectangle with side lengths %f and %f is: %f\n", side_a, side_b, perim);
                                    break;
                                }
                                case(2):
                                {
                                    area = side_a*side_b;
                                    printf("\nThe area of a rectangle with side lengths %f and %f is: %f\n", side_a, side_b, area);
                                    break;
                                }
                                default:

                                    printf("Please chose 1 for perimeter or 2 for area.\n");
                                    break;
                            }
                        }

                     }
                system("PAUSE");
                system("cls");
                select_main = 0;  //Returns to main loop for shape selection after break
                break;

                case(2):  //Circle
                    {
                    select_circ = 0;
                    system("cls");  //This command clears the screen. Unfortunately it appears to be unique to Windows. For POSIX use "system(clear);"
                    printf("You have selected the Circle. A circle is the set of all points in a plane that are equidistant from a central point."
                           " The distance between any point and this central point is called the 'radius'. Please input a radius length, followed"
                           " by the number corresponding to the operation you would like to perform.\n\n");
                    printf("radius = ");
                    scanf("%f", &rad);
                    printf("\n1.Circumference\n2.Area\n\nYour selection is: ");

                        while(select_circ<1 || select_circ>2)   //Loops while select_rect value is anything other than 1,2. Avoids complications when erroneous integers are entered
                        {
                            scanf("%d", &select_circ);          //Reads case selection. 1 for circumference, 2 for area.

                            switch(select_circ)
                            {
                                case(1):
                                {
                                    circum = 2*PI*rad;
                                    printf("\nThe circumference of a circle with radius %f is: %f\n", rad, circum);
                                    break;
                                }
                                case(2):
                                {
                                    area = PI*pow(rad,2);
                                    printf("\nThe area of a circle with radius %f is: %f\n", rad, area);
                                    break;
                                }
                                default:

                                    printf("Please chose 1 for circumference or 2 for area.\n");
                                    break;
                            }
                        }
                    }

                system("PAUSE");
                system("cls");
                select_main = 0;  //Returns to main loop for shape selection after break
                break;

                case(3):  //Cylinder
                    {
                    select_cylndr = 0;
                    system("cls");  //This command clears the screen. Unfortunately it appears to be unique to Windows. For POSIX use "system(clear);"
                    printf("You have selected the Cylinder. A cylinder is a basic curvilinear shape that is enclosed by the set of all points"
                           " that are equidistant from a central point for a certain length(radius), along an axis, and two planes perpendicular"
                           " to said axis. Please input a radius length and a height, followed by the number corresponding to the operation"
                           " you would like to perform.\n\n");
                    printf("radius = ");
                    scanf("%f", &rad);
                    printf("height = ");
                    scanf("%f", &height);
                    printf("\n1.Surface Area\n2.Volume\n\nYour selection is: ");

                        while(select_cylndr<1 || select_cylndr>2)  //Loops while select_rect value is anything other than 1,2. Avoids complications when erroneous integers are entered
                        {
                            scanf("%d", &select_cylndr);           //Reads case selection. 1 for area, 2 for volume.

                            switch(select_cylndr)
                            {
                                case(1):
                                {
                                    area = 2*(PI*rad*height);
                                    printf("\nThe surface area of a cylinder with radius %f and height %f is: %f\n", rad, height, area);
                                    break;
                                }
                                case(2):
                                {
                                    volume = PI*pow(rad,2)*height;
                                    printf("\nThe volume of a cylinder with radius %f and height %f is: %f\n", rad, height, volume);
                                    break;
                                }
                                default:

                                    printf("Please chose 1 for surface area or 2 for volume.\n");
                                    break;
                            }
                        }
                    }

                system("PAUSE");
                system("cls");
                select_main = 0;  //Returns to main loop for shape selection after break
                break;

                case(4): //Sphere
                    {
                    select_sphere = 0;
                    system("cls");  //This command clears the screen. Unfortunately it appears to be unique to Windows. For POSIX use "system(clear);"
                    printf("You have selected the Sphere. A Sphere is a circular object in 3-dimensional space that is perfectly round."
                           " Just as a circle is the set of all points that are equidistant from a central point for a certain radius in 2 dimensions,"
                           " the same is true for a sphere but in 3 dimensions. The radius for a given sphere is the same as its 2-dimensional analogue."
                           " Please enter a value for the radius, followed by the number corresponding to the operation you would like to perform.\n\n");
                    printf("radius = ");
                    scanf("%f", &rad);
                    printf("\n1.Surface Area\n2.Volume\n\nYour selection is: ");

                        while(select_sphere<1 || select_sphere>2)  //Loops while select_rect value is anything other than 1,2. Avoids complications when erroneous integers are entered
                        {
                            scanf("%d", &select_sphere);          //Reads case selection. 1 for surface area, 2 for volume.

                            switch(select_sphere)
                            {
                                case(1):
                                {
                                    area = 4*(PI*pow(rad,2));
                                    printf("\nThe surface area of a sphere with radius %f is: %f\n", rad, area);
                                    break;
                                }
                                case(2):
                                {
                                    volume = 0.75*(PI*pow(rad,3));
                                    printf("\nThe volume of a sphere with radius %f is: %f\n", rad, volume);
                                    break;
                                }
                                default:

                                    printf("Please chose 1 for surface area or 2 for volume.\n");
                                    break;
                            }
                        }
                    }

                system("PAUSE");
                system("cls");
                select_main = 0;  //Returns to main loop for shape selection after break
                break;

                case(5):  //Exit
                    {

                    system("cls");    //Unfortunately this command appears to be unique to Windows. For POSIX use "system(clear);"
                    printf("\n**Thanks! Goodbye.**\n");
                    break;

                    }

                default:

                    system("cls");
                    printf("**Please choose an integer from 1 to 5!**\n\n");
                    break;

            }
        }

      system("PAUSE");
return 0;
}
