In: Computer Science
6) c programming Case study: In a certain building at a top secret research lab, some yttrium-90 has leaked into the computer analysts’ coffee room. The leak would currently expose personnel to 150 millirems of radiation a day. The half-life of the substance is about three days, that is, the radiation level is only half of what is was three days ago. The analysts want to know how long it will be before the radiation is sown to a safe level of 0.466 millirem a day. They would like a chart that displays the radiation level for every there days with message unsafe or sage after every line. The chart should stop just before the radiation level is on-tenth of the sage level, because the more cautious analysts will require a safety factor of 10.
I have used a series of '|' to represent a bar in C.
The code for the same is:
#include<stdio.h>
int main(){
double curr_rad = 150;
double sage_val = 0.466;
//I am using the '|' to draw a bar representing the radiation level
//One | represents 8 millirem radiation
while(curr_rad > (sage_val/10)){
//draw the level bar
for(int i = 1; i <= (int)(8*curr_rad); i++)
printf("|");
//printing the radiation level
printf("\nradiation value: %f", curr_rad);
//if current radiation level is greater than sage value
//print that the state is unsafe
if(curr_rad > sage_val)
printf("\nunsafe\n\n");
//else it is sage
else printf("\nsage\n\n");
//radiation gets reduced to half after every three days
curr_rad /= 2;
}
return 0;
}
Output:
The first two bars are looking equal in the output, but actually the series of '|' was very large as compared to the output screen. But the output is totally right.