Thread: C Programming Question Help

  1. #1
    Registered User
    Join Date
    May 2021
    Posts
    3

    Post 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. #2
    Registered User
    Join Date
    Apr 2021
    Posts
    23
    Hi, can you show what you've done so far? We don't generally do other peoples' homework entirely.

  3. #3
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,101
    Quote Originally Posted by Deka_degan0 View Post
    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. #4
    Registered User
    Join Date
    Sep 2020
    Posts
    424
    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. #5
    Registered User
    Join Date
    May 2021
    Posts
    3
    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
    Last edited by Salem; 05-17-2021 at 08:33 PM. Reason: Added [code][/code] tags - learn to do it yourself

  6. #6
    Registered User
    Join Date
    May 2021
    Posts
    3
    No, this is my first C programming language, next semester will be C++. The course is called BIT1400

  7. #7
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    338

    Thumbs up

    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
    Last edited by Structure; 05-18-2021 at 10:33 AM.
    "without goto we would be wtf'd"

  8. #8
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    When you give the answer like that you make dumber programmers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Programming Question
    By Buddha in forum C Programming
    Replies: 11
    Last Post: 05-17-2010, 03:02 PM
  2. Total newb to programming here... Question about the many programming languages. Ty!
    By tsubotakid1 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 10-05-2003, 10:32 AM
  3. C Programming Question
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 12-07-2001, 06:44 AM
  4. Programming question
    By face_master in forum C++ Programming
    Replies: 1
    Last Post: 08-26-2001, 07:00 AM

Tags for this Thread