# Thread: C Programming Question Help

1. ## C Programming Question Help

Hey everyone,

I am a uni student, studying computer technology this semester. I have trouble programming c code. Please help with this question, I have written down some answer but i dont know if its right

The Problem
Assume you are doing some renovations in your house and you want to paint a room. Your budget for painting the room is 150\$. Write a program that calculates the amount of paint needed.
a) Prompt the user to input the room’s dimensions (HxLxW)
b) Calculate and output the total area of all walls.
c) Calculate and output the amount of paint in Liters needed to paint the wall. Assume a Liter of paint covers 150 square feet.
d) Calculate the number of 3.7 Liter cans needed to paint the wall. Round the number using the “round” function from math.h library.
• Hint: save the result into a variable.
e) Output the number cans needed.
f) Assuming that a 3.7L can costs 50\$, calculate and output the cost of painting the shed.
g) Calculate and output the cost for 1, 2 and 3 coats of paint, and how far is it from the budget.

I am new to the community so please feel free to contact me and message me

2. Hi, can you show what you've done so far? We don't generally do other peoples' homework entirely.

3. Originally Posted by Deka_degan0
Hey everyone,

I am a uni student, studying computer technology this semester. I have trouble programming c code. Please help with this question, I have written down some answer but i dont know if its right

The Problem
Assume you are doing some renovations in your house and you want to paint a room. Your budget for painting the room is 150\$. Write a program that calculates the amount of paint needed.
a) Prompt the user to input the room’s dimensions (HxLxW)
b) Calculate and output the total area of all walls.
c) Calculate and output the amount of paint in Liters needed to paint the wall. Assume a Liter of paint covers 150 square feet.
d) Calculate the number of 3.7 Liter cans needed to paint the wall. Round the number using the “round” function from math.h library.
• Hint: save the result into a variable.
e) Output the number cans needed.
f) Assuming that a 3.7L can costs 50\$, calculate and output the cost of painting the shed.
g) Calculate and output the cost for 1, 2 and 3 coats of paint, and how far is it from the budget.

I am new to the community so please feel free to contact me and message me
What course is this an assignment for? Have you taken any course in the C Programming Language?

4. So if I was in a room 2.4m Hight x 2.5m Long and 2.0m Wide, are you able to show me how to work out the answers for questions b to g?

Why?

What I am trying to get you to do is to learn how the problem works, so that you can use that knowledge when it comes to writing your code.

5. Code:
/*Room Paint and Whitewash*/
#include <stdio.h>
int main()
{
float room_width, room_length, room_height, door_length, door_height, window_length, window_height, paint_area, whitewash_area;
printf("Enter dimensions of room (Length, Width, Height) in order:\n");
scanf("%f%f%f", &room_length, &room_width, &room_height);
printf("Enter dimensions of door (Length, Height) in order:\n");
scanf("%f%f", &door_length, &door_height);
printf("Enter dimensions of door (Length, Height) in order:\n");
scanf("%f%f", &window_length, &window_height);
//Paint area = Area of four walls - area of door - area of 2 windows
paint_area = 4*room_length*room_height - door_length*door_height - 2*window_length*window_height;
//Whitewash area = area of roof
whitewash_area = room_length*room_width;
printf("Area to be painted:\t%f\n", paint_area);
printf("Area to be whitewashed:\t%f\n", whitewash_area);
I wrote this through my notes

6. No, this is my first C programming language, next semester will be C++. The course is called BIT1400

7. work out the answers for questions
Code:
#include <stdio.h>

int main() {

int cansRequired = 0;
float height = 0, area = 0;
float length = 0, width = 0;
float litersNeeded = 0.0;

float literCovers = 150;
float paintCanSize = 3.7;
float paintCanCost = 49.99;

printf("Enter the rooms dimensions in square feet:\n");
printf( "length:" ); scanf( "%f", &length );
printf( "width:" ); scanf( "%f", &width );
printf( "height:" ); scanf( "%f", &height );

area = (length*width*height);
litersNeeded = (area / literCovers);
cansRequired = (int)(litersNeeded/paintCanSize)+1;

printf( "Room area: %.2f \n", area );
printf( "1 Liter covers %.2f square feet.\n", literCovers );
printf( "The room requires %.2f liters of paint.\n", litersNeeded );
printf( "Paint comes in 3.7 Liter containers.\n" );
printf( "The room will require %i paint cans.\n", cansRequired );
printf( "A can of paint costs \$%.2f.\n", paintCanCost );
printf( "The paint will cost: \$%.2f.\n", (paintCanCost*cansRequired) );

float budget = 150.00 ;
float cost = (paintCanCost*cansRequired);

printf( "Your budget is %.2f and your cost is %.2f.\n", budget, cost );

if (budget >= cost) {
printf( "You can afford the paint.\n");
} else {
printf( "You can't afford the paint.\n");
}

return 0;
}
Round the number using the “round” function from math.h library.

Code:
gcc -lm

8. When you give the answer like that you make dumber programmers.