Need help with rounding in simple program
I've copied my code below, basically I'm making a program where the user gives the dimensions of the room to be painted, and the number of windows, doors, and skylights each have a standard area windows -12, doors -20, and skylights -24sqft. These are added together, and subtracted from the surface area of the room (Roof, and four walls). Then I must calculate how many gallons of paint is needed (220sqft / gal). After dividing the paint area by 220, I end up with the real value for example a 10x20x10 room with 3 windows, 2 doors, and 1 skylight, you need roughly 3.18 gallons. Now what i need is for the program to round the remainder up to 1, so that it would say 4 gallons, because you'll need to buy 4 to paint the room, because you can't buy .18 gallons these days lol. :biggrin: Now my class is still in the early steps of C, even though i know how to use if's and else's, I'm not supposed to know those yet. The way I have it now, it work, but if the area to be painted with windows, and etc. is subtracted, the program will output 1 less gallon then it actually needs since the mod of 220 & 220 is 0. I tried earlier using doubles, and using modifiers in front of the %lf, but I couldn't get it to round up always. If you could help me find a roughly break proof method to solving this dilemma, I would truly appreciate it.
Code:
//Insert Header For code here:
#include <stdio.h>
int main() {
printf("\n##### - ##### - ##### #### - ####@####.edu\n"); //header
int length, width, height, windows, doors, skylights, paintarea, gallons;
// User Prompting section
printf("\nEnter room length: ");
scanf("%d",&length);
printf("Enter room width: ");
scanf("%d",&width);
printf("Enter room height: ");
scanf("%d",&height);
printf("Enter number of windows: ");
scanf("%d",&windows);
printf("Enter number of doors: ");
scanf("%d",&doors);
printf("Enter number of skylights: ");
scanf("%d",&skylights);
printf("\n");
// converting user values into area for subtraction from dimensions of room.
windows = windows * 12;
doors = doors * 20;
skylights = skylights * 24;
// Adding each set of walls, and roof to the total area to be painted in sq ft.
paintarea = (width * height) * 2;
paintarea = paintarea + ((length * height) * 2);
paintarea = paintarea + (length * width);
// Removing areas of windows, doors, and skylights.
paintarea = paintarea - (windows + doors + skylights);
// Dividing the totoal area by 220 since each gallon of paint cover 220 sqft, and will use printf formating to round the answer up to nearest gallon.
gallons = paintarea / 220;
gallons = gallons + ((paintarea%220) - ((paintarea%220)-1));
printf("\nThe number of gallons needed would be %d. \n",gallons);
return 0;
}