02-07-2004, 12:35 PM
|
#1 (permalink)
|
Devils Cabana Boy
Location: Central Coast CA
|
another simple C question
Ok this program is the same as the last one, i am to enter 3 variables height width and length and it spits out the volume, the square footage and the ratio between the length and the width, it does everything except the ratio it rounds to the nearest hole number, even though it is stored as a double.
Thanks in advance.
Quote:
#include <stdio.h>
main(void)
{
int nRoomLength=0, nRoomWidth=0, nRoomHeight=0;
double dWidthToLength=0 ; /* width/length */
short int nRoomVolume=0 ; /* nRoomWidth * nRoomLength * nRoomHeight*/
unsigned int nRoomArea=0 ; /* nRoomWidth * nRoomLength */
printf("Please enter a value for the room width:");
scanf("%d", &nRoomLength);
printf("Please enter a value for the room length::");
scanf("%d", &nRoomWidth);
printf("Please enter a value for the room height::");
scanf("%d", &nRoomHeight);
nRoomArea = nRoomLength * nRoomWidth;
nRoomVolume = nRoomLength * nRoomWidth * nRoomHeight;
dWidthToLength = (nRoomWidth / nRoomLength);
printf("The area of the floor of the room is: %d\n", nRoomArea);
printf("The volume of the room is: %d\n", nRoomVolume);
printf("The ratio of the width to the length is: %lf\n\n", dWidthToLength);
printf("Variable Dump: \n\n");
printf("Variable\tNumber of\tAddress of\tValue in\n");
printf("Name\t\tBytes\t\tVariable\tVariable\n");
printf("nRoomWidth\t%d\t\t%p\t%d\n",sizeof(nRoomWidth),&nRoomWidth,nRoomWidth);
printf("nRoomWidth\t%d\t\t%p\t%d\n",sizeof(nRoomLength),&nRoomLength,nRoomLength);
printf("nRoomWidth\t%d\t\t%p\t%d\n",sizeof(nRoomHeight),&nRoomHeight,nRoomHeight);
printf("nRoomWidth\t%d\t\t%p\t%lf\n",sizeof(dWidthToLength),&dWidthToLength,dWidthToLength);
printf("nRoomWidth\t%d\t\t%p\t%d\n",sizeof(nRoomVolume),&nRoomVolume,nRoomVolume);
printf("nRoomWidth\t%d\t\t%p\t%d\n",sizeof(nRoomArea),&nRoomArea,nRoomArea);
}
|
__________________
Donate Blood!
"Love is not finding the perfect person, but learning to see an imperfect person perfectly." -Sam Keen
|
|
|