EG Information
Training Missions
Knowledge Bank
|
|
Enigma Group's Code Bank
Tins in a boxBy: mofm - Date Submitted: 2009-07-25 17:43:58 #include <stdio.h> //header files
#include <stdlib.h> //header files
float cyl_diameter,cyl_height,cyl_radius,cyl_radius2,cyl_answer,cyl_vol,total_cyl_vol,waste //Cylinder variables
float cont_height,cont_width,cont_lenght,cont_area,cont_vol,cont_answer //Container variables
int fitinbox
char buff[20]//buffer
float cylinder_vol (float cyl_height,float cyl_diameter) //Work out
{
cyl_radius = cyl_diameter / 2 // calculate radius
cyl_radius2 = cyl_radius*cyl_radius //calculate radius squared
cyl_answer= 3.14*cyl_radius2*cyl_height//calculate volume
return cyl_answer//return area to main function
}
float container_vol(float lenght,float height,float width) //works out the container volume
{
cont_answer= lenght*height*width
return cont_answer
}
int amount_fits(float diameter,float lenght,float width,float height) //works out the amount of cylinders that fits in a box
{
int answer
answer = (int)(lenght / diameter) * (int)(width / diameter) * (int)(height / cyl_height)
return answer
}
void main ()
{
do{
printf ("Enter the height of the Cylinder in CM: ")
cyl_height = atof(gets(buff))
if (cyl_height <=0)
{
printf("Height Entered is To low.n")
}
}while(cyl_height <=0)
do{
printf ("Enter the diameter of the Cylinder in CM: ")
cyl_diameter = atof(gets(buff))
if (cyl_diameter <=0)
{
printf("Diameter Entered is To low.n")
}
}while(cyl_diameter <=0)
do{
printf ("Enter the Width of the box in CM: ")
cont_width = atof(gets(buff))
if (cont_width <=0)
{
printf("Width Entered is To low.n")
}
}while(cont_width <=0)
do{
printf ("Enter the Length of the box in CM: ")
cont_lenght = atof(gets(buff))
if (cont_lenght <=0)
{
printf("lenght Entered is To low.n")
}
}while(cont_lenght <=0)
do{
printf ("Enter the Height of the box in CM: ")
cont_height = atof(gets(buff))
if (cont_height <=0 cyl_height > cont_height)
{
printf("Height Entered is To low.n")
}
}while(cont_height <=0 cyl_height > cont_height)
/*The above code Gets input from user and makes sure the input is above 0 if not it will
tell the use thir is an error and show the input prompt again*/
cyl_vol = cylinder_vol(cyl_height,cyl_diameter) // calls function to work out cylinder volume
cont_vol= container_vol(cont_lenght,cont_height,cont_width)//calls function to work out container volume
fitinbox = amount_fits(cyl_diameter, cont_lenght, cont_width, cont_height)
// above calls function to work out the amount of tins that fit in a box
total_cyl_vol = cyl_vol * fitinbox // this works out the total volume used inside the box by the tins
waste = cont_vol - total_cyl_vol //this takes the total volume used by the tins and takes it from the box volume
printf("You can fit %d cylinders in boxn",fitinbox) //Shows user the program output
printf ("The waste volume is: %2.2f CM3n",waste)
}
|
| Return to
ajax category list |
|
|
Who's Online
487 Guests, 99 Users Diznablo, ckryptix, Nicid1, Ios, viper0i0, rabbidmind, Nasrudin, CollapsingWalls, mehtaparag, bitstrike, jnony, C, Nusquam-Redono-Sapientia, bazcrown, saifulfaizan, The End, Ultraminor, psychomarine, st3alth, themastersinner, pgmrlink, login, lionaneesh, ishkur88, mahraja, Mac, chekifr, gandalf88, Vap0r, t0ast, tantrum6226, BnE, Distorted, Psiber_Syn, Ausome1, invas10n, oldgoat, freedaysbecumei, BinaryShinigami, Rex_Mundi, Red_beard, Strobeflux, s0m3nak3dguy, Descent, teehee, machupicchu, Genetix, Anandarl, NotMyOwn, thegamerdude, Godzila, popo12341234, RedEvolution, velocity_b, myne17, teto111, aVoid, Central-Gsm, 1101, JackalReborn, InjectioN, h4lted, c0re, DisPater, markt4death, splatta, Jackowacko, saint556, Pyron2312, Azerion, howsens, white.hat.gone.bad, vazzilly, pwunkz, Inverted, QuarterCask, Infernoe11, deskata, cr4ck3rj4ck, Blizer, jasonmax, j0sh, gwenwavor, N4g4c3N, spizeyboy, Network X, Uino59, Jae Cee, ianFDK, saykov, medhaavee, zofy, demonkiller410, Stumble, SaMTHG, kishore, Raze, helasraizam, Venom1019 |
| |
|
|
|
|
|