// Author: Thomas Kilbride // CSE 121 // Assignment: Tank // Filename: tank.c // Creation Date: Jul. 16 2010 // Purpose: This program is designed to calculate the density of water in a // cylindrical tank assuming a temperature of 22C and 0 salinity. /* Declarations */ #include <stdio.h> //C Standard Input and Output Library #include <stdlib.h> // Defines several general purpose functions, including dynamic memory management random number generation, communication with the environment, integer arthmetics, searching, s$ #include <math.h> // library with Pi (M_PI) #define DENSITY 997.770 // Water's density in kg/m at 22C with 0 salinity /* End Declarations */ int introduction(void) { printf("\nGreetings %s!\nThis program is designed to calculate the mass of water in a cylindrical tank assuming a temperature of 22C and 0 salinity.\n", getenv("USER")); } int main(void) { char finished = 'x'; double diameter, height, volume, mass; char yes[] = "yY"; char no[] = "nN"; introduction(); /* Greet the user */ do { /* Check to be sure a line break does not exist in the user's response because if they press enter at the prompt they should be asked a second time */ if(finished != '\n' ) { /* Check if the user is finished, if so break out of the do loop */ if(finished == yes[0] || finished == yes[1]) { break; } /* Begin calculation construct */ printf("Please enter all units in their SI base value (i.e. kilograms, meters, etc.).\n\n"); printf("Diameter: "); scanf("%lf",&diameter); printf("Height: "); scanf("%lf",&height); volume=(M_PI*pow(diameter/2,2))*height; mass=volume*DENSITY; printf("Diameter = %0.2lf m,\011Height = %0.2lf m\n" "Volume = %0.2lf m,\011Mass = %0.2lf kg", diameter, height, volume, mass); /* end calculation construct */ /* Ask the user if they are finished */ printf("\nFinished (y/n)? "); } /* define the parameters of the "do while" loop, use getchar to sanatize user input */ } while((finished = getchar()) != EOF); printf("\nGoodbye!\n"); return 0; }