I have tried to round the float point number to a whole number in 2 different ways:
I am trying to round up on the cans of paint. I have tried by using cans = (int)(surface + 0.5)/300; I still get the answer 0 cans even though the initial value of the surface variable is .61. I then tried cans = (int)(surface * 10)/300; which gave me 6 cans. Is there a round function with C that works like the round function in a sql statement?
Please see my code to help you understand what I am doing.
#include <stdio.h>
int main()
{
float width; /* integer to hold the width value */
float length; /* integer to hold the length value */
float area; /* integer to hold the area value */
float yard; /* integer to hold the yard value */
float height; /* integer to hold the height value */
float surface; /* integer to hold the surface value */
int cans; /* integer to hold the cans of paint value */
printf("Please enter the width of the room:\n"); /* ask for the width */
scanf("%f", &width); /* intake the width */
printf("Please enter the length of the room:\n"); /* ask for the length */
scanf("%f", &length); /* intake the length */
printf("Please enter the height of the walls\n"); /* ask for the height */
scanf("%f", &height); /* intake the height */
area = width + length; /* variable of area w + l gives the value */
yard = area /3; /* variable of yard is w + l /3 the value */
surface = (height + width + length) *4; /* variable of surface is h + w + l *4 walls = the value */
cans = (int)(surface * 10)/300; /* variable of cans is h + w + l *4/300sq.ft= the value */
printf("You will need %f square feet of carpet\n", area); /* output the area to screen */
printf("You will need %f square yards of carpet\n", yard); /* output the yards to screen */
printf("The walls are %f square feet\n", surface); /* output the surface to screen */
printf("You will need %d cans of paint\n", cans); /* output the cans to screen */
scanf("Enter anything:\n",&cans); /* a pause to be commented out */
return 0;
}