Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

im working on a C program that uses input to calculate area, paint needed and ca

ID: 3880514 • Letter: I

Question

im working on a C program that uses input to calculate area, paint needed and cans. this is my code

#include <stdio.h>
#include <math.h> // Note: Needed for math functions in part (3)

int main(void) {
float area,h,w;
double g;
printf("Enter wall height (feet): ");
scanf("%f",&h);
printf("Enter wall width (feet): ");
scanf("%f",&w);
// FIXME (1): Prompt user to input wall's width

// Calculate and output wall area
area = h*w; // FIXME (1): Calculate the wall's area
printf("Wall area: %f square feet ",area); // FIXME (1): Finish the output statement


g = area/350;
printf("Paint needed: %f gallons",g);


// FIXME (2): Calculate and output the amount of paint in gallons needed to paint the wall

printf(" Cans needed:%f can(s) ",round(g));
// FIXME (3): Calculate and output the number of 1 gallon cans needed to paint the wall, rounded up to nearest integer

return 0;
}

for the most part its correct, but theres one part thats wrong

with the inout for height and width being 12 and 15

the output should be

Enter wall height (feet):

Enter wall width (feet):

Wall area: 180 square feet

Paint needed: 0.514286 gallons

Cans needed: 1 can(s)

but for some reason im getting

Enter wall height (feet):

Enter wall width (feet):

Wall area: 180.000000 square feet

Paint needed: 0.514286 gallons

Cans needed:1.000000 can(s)

when im rounding for the number of cans it should show up as 1, not 1.000000 can someone help me revise my code so that when i round for cans it gives me a whole number please

Explanation / Answer

Answer : -

For this problem you can print as follows:

printf(" Cans needed:%.0f can(s) ",round(g));

this will automatically roundoff your digit.

for example round(g) return 0.5 the above will print 1

else if the value return is less then x.5 then it will print x where x is any whole number or integer.