Figure 5.16 Program to Compute Radiation Levels /* * Calculates and displays a table showing the safety level of a coffee room. */ #include #define SAFE_RAD 0.466 /* safe level of radiation */ #define SAFETY_FACT 10.0 /* safety factor */ int rad_table(double init_radiation, double min_radiation); int main(void) { int day; /* day user can enter room */ double init_radiation, /* radiation level right after leak */ min_radiation; /* safe level divided by safety factor */ /* Compute stopping level of radiation. */ min_radiation = SAFE_RAD / SAFETY_FACT; /* Prompts user to enter initial radiation level */ printf("Enter the radiation level (in millirems)> "); scanf("%lf", &init_radiation); /* Displays table */ day = rad_table(init_radiation, min_radiation); /* Display day the user can enter the room. */ printf ("\nYou can enter the room on day %d.\n", day); return (0); } /* * Displays a table showing the radiation level and safety status every 3 * days until the room is deemed safe to enter. Returns the day number for * the first safe day. * Pre : min_radiation and init_radiation are defined. * Post: radiation_lev <= min_radiation */ int rad_table(double init_radiation, double min_radiation) { int day; /* days elapsed since substance leak */ double radiation_lev; /* current radiation level */ day = 0; printf("\n Day Radiation Status\n (millirems)\n"); for (radiation_lev = init_radiation; radiation_lev > min_radiation; radiation_lev /= 2.0) { if (radiation_lev > SAFE_RAD) printf(" %3d%5c%9.4f Unsafe\n", day, ' ', radiation_lev); else printf(" %3d%5c%9.4f Safe\n", day, ' ', radiation_lev); day += 3; } return (day); } Enter the radiation level (in millirems)> 150.0 Day Radiation Status (millirems) 0 150.0000 Unsafe 3 75.0000 Unsafe 6 37.5000 Unsafe 9 18.7500 Unsafe 12 9.3750 Unsafe 15 4.6875 Unsafe 18 2.3438 Unsafe 21 1.1719 Unsafe 24 0.5859 Unsafe 27 0.2930 Safe 30 0.1465 Safe 33 0.0732 Safe You can enter the room on day 36.