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
415 Guests, 94 Users hemiptera, chrbarrol, dark_void, towncrown, EngGi235, blink_212, klesco, vapour, Ausome1, _InSane_, LordHelmet, BnE, N4g4c3N, ThaKeeper, th3punish3r, locust, c0re, iwanlearn, Anderl, ghostraider100, Ghostrider, eliking510, harsha2hack, NotMyOwn, Calumoo, MajorDeath, Rex_Mundi, sabre725, bhoang93, r!v3rTw!ggz, jarlskov, invas10n, snozzberries, Nusquam-Redono-Sapientia, data, zeth, psychomarine, yuka, DnA-Ender, 454447415244, Ultraminor, T-Metal, antibubbles, raven001, aVoid, Psiber_Syn, sirEgghead, Protagoras, niggletandco, Vahakn, Chaplin, BinaryShinigami, zoegeorgica, hacker807, Red_beard, eviscerator, TheFender, InjectioN, totalnoob, Posix, obrigadoo, cul8er, Mcasdf, teehee, Ops, Protest123, Blizer, gabel, Marian, Edika, zofy, Nasrudin, dochaley, TheRetech, j0sh, kcaz, cool.nik, Sand, SaMTHG, fawk3s, rajabaja, avalor, hettoo, mat_2010, barbseven, daandeveloper33, tommy1092, Likantrop7, sajan619, Knuppel, Distorted, Bloodmaster25, buffer, apablo |
| |
|
|
|
|
|