Thread: Optimizing Number of Tables in a Room

  1. #1
    Registered User
    Join Date
    Jan 2020
    Posts
    1

    Optimizing Number of Tables in a Room

    I'm trying to make a code for optimal seating arrangement to find the maximum number of people that can be seated given length and with or room, tables, and the space between each table.

    How can I make my program optimize the number of tables the the room can fit, given the room's restrictions?

    I'm thinking of using if and then statements, as well as greater than, less than, or greater to or equal to statements. But I dont know how to utilize them. Or if it would even be efficient to do so.

    I started writing the code. But I cant even write an arithmetic operational in order to find the total number of tables a room can fit

    Code:
    #studio.h
    
    Int main( )
    
    {
    Int LengthandWidthofRoom;
    Int LengthandWidthofTables;
    Int PeoplePerTable;
    Int SpaceBetweenTables;
    Int NumberofTables;
    Int TotalPeople;
    
    LengthandWidthofRoom>=TotalNumberofTables+SpaceBetweenTables
    
    Printf("What is the length and width of the room?" );
    Scanf("%d", &LengthandWidthofRoom);
    
    Printf("What is the length and width of each table?" );
    Scanf("%d", &LengthandWidthofTables);
    
    Printf("How many people are seated at each table?" );
    Scanf("%d", PeoplePerTable);
    
    Printf("How wide is the space between each table?" );
    Scanf("%d", &SpaceBetweenTables);
    
    TotalPeople = (PeoplePerTable*NumberofTables) + SpaceBetweenTables
    
    return0;
    }

  2. #2
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,736
    Is that pseudocode or have you been skipping class? Also, the problem description seems a bit vague. Is the description your interpretation of the description or the actual description? Are the tables meant to be square? How big are the seats?

  3. #3
    Registered User
    Join Date
    Dec 2017
    Posts
    834
    Example input and associated output would be helpful.

    @Hodor, I bet it was typed on an iphone!
    The world hangs on a thin thread, and that is the psyche of man. - Carl Jung

  4. #4
    Registered User
    Join Date
    Apr 2011
    Location
    dust
    Posts
    70
    Int LengthandWidthofRoom;
    Int LengthandWidthofTables;
    How can you declare a single variable to hold 2-Dimension (Length and Width) value?
    Use two different variable to hold the value from user.
    Your question is about
    Optimizing Number of Tables in a Room
    What have you tried as a solution to calculate the number of tables required or can be occupied in a room?

  5. #5
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    240
    In Theory...
    Code:
    #include <stdio.h>
    
    int main(int args,char *argv[]) {
    
        float roomWidth = 20, roomLength = 30;
        float tableWidth = 4, tableLength = 7;
        float spaceWidth = 4, spaceLength = 6;
    
        float floorSpace = (roomWidth*roomLength);
        float tableSize = ((tableWidth+(spaceWidth*2))*(tableLength+(spaceLength*2)));
        int tableCount = (floorSpace/tableSize);
    
        printf("In a room of size [%.2f x %.2f]. ", roomWidth,roomLength);
        printf("You have a total area of [%.2f]. ", floorSpace);
        printf("Considering tables that are [%.2f x %.2f], ", tableWidth,tableLength);
        printf("a width spacing of [%.2f] on both sides ", spaceWidth);
        printf("and a length spacing of [%.2f] on both sides. ", spaceLength);
        printf("Since a table and the space around it requires [%.2f]. ",tableSize);
        printf("You can fit a maximum of [%i] tables in the room. ", tableCount );
        printf("\n");
    
        return 0;
    };
    Last edited by Structure; 3 Weeks Ago at 11:16 AM. Reason: Changed spaceWidth/spaceHeight to accomodate both sides. duh
    "without goto we would be wtf'd"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Any Room For Improvement?
    By Clinthill98 in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2010, 07:11 AM
  2. Is there a C++ Chat Room
    By kamitsuna in forum General Discussions
    Replies: 1
    Last Post: 02-25-2010, 12:45 AM
  3. C# chat room?
    By jackstrong in forum C# Programming
    Replies: 1
    Last Post: 03-19-2006, 06:32 PM
  4. C Chat Room
    By bnovc in forum C Programming
    Replies: 3
    Last Post: 06-26-2005, 08:42 PM
  5. A chat room?
    By Padawan in forum Networking/Device Communication
    Replies: 3
    Last Post: 11-19-2003, 07:32 PM

Tags for this Thread