Hello everyone
I wanted to know if is possible to give a fixed value to teh esc and enter button in order to quit or repeat teh program below...
I have a rough idea to assign teh esc button the "quit" capability but I don't know how to do so with the enter button.
CODE
/*This program will calculate the volume used by a box that contains a number of tins.
The program will also calculate the number of tins in the box and the volume wasted. */
/*width_box=Width of the box in use
height_box=Height of the box in use
lenght_box=Lenght of the box in use
width=The number of tins fitted along the width of the box
lenght=The number of tins fitted along the lenght of the box
height_tin=Height of the tin in use
diameter_tin=Diameter of the tin in use(twice the radius)
pi=is a costant used to calculate the volume of a cylinder and is equal to 3,141592
, which was rounded to 3.142
volume_used=Total volume of the tins in the box
volume_box=Volume of the box in use
volume_wasted=Volume wasted(Volume of the box-Volume Used)
layers=Number of layers of tins
tins=Total number of the tins*/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define pi 3.142
void main(void)
{
float width_box,height_box,lenght_box;
float height_tin,diameter_tin;
float volume_used,volume_box,volume_wasted;
float tins,layers;
float width,lenght;
char buff [20];
/*The user inserts details related to the width of
the box and the diameter of the tin*/
printf("Type in width details.\n");
do
{
printf("\nType in the diameter of the tin:(cm)\n" ,diameter_tin);
diameter_tin=atof(gets(buff));
if (diameter_tin <= 0.0)
{
printf("\nPlease, type in an appropriate value for this figure.\n");
}
}while(diameter_tin<=0.0);
do
{
printf("Type in the width of the box:(cm)\n" ,width_box);
width_box=atof(gets(buff));
if (width_box <= 0.0)
{
printf("\n\nPlease, type in an appropriate value for this figure.\n");
}
}while(width_box<=0.0);
printf("___________________________________________________________________\n");
/*The user inserts details related to the lenght of the box*/
printf("\nType in leght details.\n");
do
{
printf("\nType in the lenght of the box:(cm)\n",lenght_box);
lenght_box=atof(gets(buff));
if (lenght_box <= 0.0)
{
printf("\nPlease, type in an appropriate value for this figure.\n");
}
}while(lenght_box<=0.0);
printf("___________________________________________________________________\n");
/*The user inserts details related to the height of the box
and the height of the tin*/
printf("\nType in height details.\n");
do
{
printf("\nType in the height of the tin:(cm)\n",height_tin);
height_tin=atof(gets(buff));
if (height_tin <= 0.0)
{
printf("\nPlease, type in an appropriate value for this figure.\n");
}
}while(height_tin<=0.0);
do
{
printf("Type in the height of the box:(cm)\n",height_box);
height_box=atof(gets(buff));
if (height_box <= 0.0)
{
printf("\nPlease, type in an appropriate value for this figure.\n");
}
}while(height_box<=0.0);
printf("___________________________________________________________________\n");
/*The number of layers is defined here*/
layers=height_box/height_tin;
layers=(int) layers;/*Note the use of cast*/
/*The values lenght and width are defined here in order to gain the correct value for tins*/
lenght=lenght_box/diameter_tin;
lenght=(int)(lenght);
width=width_box/diameter_tin;
width=(int)(width_box/diameter_tin);
/*tins is defined here*/
tins=lenght*width*layers;
tins=(int) tins;
printf("\nThe total number of tins in the box is:%8.0f \n",tins);/*No matter how many decimal
places are positioned on the float value,this still appears as a whole number.*/
/*volume_used is defined*/
volume_used=(diameter_tin/2)* (diameter_tin/2) * height_tin * pi;
printf("\nThe volume used by the tin is: %8.2f",volume_used);
printf("cm3\n");
/*volume_box is defined here*/
volume_box=height_box*lenght_box*width_box;
printf("\nThe volume used by the box is: %8.2f",volume_box);
printf("cm3\n");
/*volume_wasted is defined here*/
do
{
volume_wasted=volume_box-volume_used;
printf("\nThe volume wasted is: %8.2f",volume_wasted);
printf("cm3\n");
if (volume_wasted <=0.0)
{
printf("There isn't any volume wasted.");
}
}while(volume_wasted <=0.0);
printf("\n_______________________________________________________\n");
/*The inputs inserted from the user are displayed.*/
printf("The following details are the values you have inserted.");
printf("\nWidth of Box: %8.2f",width_box);
printf("cm");
printf("\nHeight of Box: %8.2f",height_box);
printf("cm");
printf("\nLenght of Box: %8.2f ",lenght_box);
printf("cm\n");
printf("\nDiameter of Tin: %8.2f",diameter_tin);
printf("cm");
printf("\nHeight of tin: %8.2f",height_tin);
printf("cm");
printf("\nPress any key to quit....");
getch();
}