Like Tree5Likes

Help Needed On A Program

This is a discussion on Help Needed On A Program within the C Programming forums, part of the General Programming Boards category; You don't appear to have any formulas -- you go straight from reading the numbers to printing the output without ...

  1. #31
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You don't appear to have any formulas -- you go straight from reading the numbers to printing the output without doing any calculations in between. EDIT: No wait, you're just printing the numbers without doing any reading. When you compile the code, your compiler says:
    Code:
    warning: 'nwidth_table' is used uninitialized in this function
    which is true, so you should fix that.
    Last edited by tabstop; 09-11-2011 at 04:43 AM.

  2. #32
    Registered User
    Join Date
    Sep 2011
    Posts
    56
    So reading the assignment for problem A, is this coding what my professor is looking for?

  3. #33
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Did you fix the errors spotted above? You also must not hard-code in the numbers 50, 30, etc, but read them in from the user. Also, you are assuming that all the tables in the room are going to be facing the same way, and you may not necessarily be able to make that assumption (it doesn't quite work in the example, but if that room had been a bit wider you could have gotten a row of vertically-oriented tables down the right side for some extra people, eg).

  4. #34
    Registered User
    Join Date
    Sep 2011
    Posts
    56
    so basically i have to use scanf command to ask the user to put the 50 and 30 in, n then basically everything is set right?

  5. #35
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Assuming you fixed all the errors spotted above, of which there are currently three (misspelled variable name, use of a variable to initialize itself, and a broken formula). For instance, you should draw some other rooms and check: if I draw, eg, an 18 x 14 room with 6x2 tables and 2 feet on each side, and 10 people at a table, you can get 60 people.

  6. #36
    Registered User
    Join Date
    Sep 2011
    Posts
    56
    hey do u have a gamil so I can chat with you for like 15 min, my assignment is due on tuesday and I just have couple more questions to ask?

  7. #37
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Perspolice1993 View Post
    so basically i have to use scanf command to ask the user to put the 50 and 30 in, n then basically everything is set right?
    Look at the problem... Don't just breeze over it... STUDY it...

    You need to ask your user for the length of the room, the width of the room, the length of the tables, the width of the tables, and the distance between tables.
    Oddly enough you print the questions but never ask for the input...

  8. #38
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Perspolice1993 View Post
    hey do u have a gamil so I can chat with you for like 15 min, my assignment is due on tuesday and I just have couple more questions to ask? email me at president@whitehouse.gov and then we can chat later on tonight, if you don't mind.
    No I Don't publish my email address here... And wouldn't spend time with this even if I did. This is your problem to solve, not mine.
    rags_to_riches likes this.

  9. #39
    Registered User
    Join Date
    Sep 2011
    Posts
    56
    can you at least tell me why when i do this code it asks the first question, but when i put 50 30 it prints the second and third question

    Code:
    printf ("What are the length and width of the room (in feet)?\n");
        scanf("%d, %d\n", &length_of_room, &width_of_room);
    
        printf ("What are the length and width of each table?\n");
        scanf("%d, %d\n", &length_of_table, &width_of_table);
    
        printf ("How much space is required between each table?\n");
        scanf("%d\n", &space_walls_tables);
    
        printf ("What is the max number of people per table?\n");
        scanf("%d", &people_per_table);

  10. #40
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Perspolice1993 View Post
    can you at least tell me why when i do this code it asks the first question, but when i put 50 30 it prints the second and third question

    Code:
    printf ("What are the length and width of the room (in feet)?\n");
        scanf("%d, %d\n", &length_of_room, &width_of_room);
    
        printf ("What are the length and width of each table?\n");
        scanf("%d, %d\n", &length_of_table, &width_of_table);
    
        printf ("How much space is required between each table?\n");
        scanf("%d\n", &space_walls_tables);
    
        printf ("What is the max number of people per table?\n");
        scanf("%d", &people_per_table);
    Lose the \n from your scanf()...

    Like this...

    Code:
    printf ("What are the length and width of the room (in feet)?  ");
        scanf("%d, %d", &length_of_room, &width_of_room);
    
        printf ("\nWhat are the length and width of each table?  ");
        scanf("%d, %d", &length_of_table, &width_of_table);
    
        printf ("\nHow much space is required between each table?  ");
        scanf("%d", &space_walls_tables);
    
        printf ("\nWhat is the max number of people per table?  ");
        scanf("%d", &people_per_table);
        printf("\n\n");
    See how nicelty that sits on your screen?

    Now... go look up scanf() in your C Library Documentation... (Yep, I'm saying "Read The Help File")
    Last edited by CommonTater; 09-11-2011 at 03:20 PM.

  11. #41
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Or you can fix the problem by keeping the \n but losing the , from your scanf format string, or by typing in a comma when you enter the numbers.

  12. #42
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    Quote Originally Posted by Perspolice1993 View Post
    can you at least tell me why when i do this code it asks the first question, but when i put 50 30 it prints the second and third question

    Code:
    printf ("What are the length and width of the room (in feet)?\n");
        scanf("%d, %d\n", &length_of_room, &width_of_room);
    
        printf ("What are the length and width of each table?\n");
        scanf("%d, %d\n", &length_of_table, &width_of_table);
    
        printf ("How much space is required between each table?\n");
        scanf("%d\n", &space_walls_tables);
    
        printf ("What is the max number of people per table?\n");
        scanf("%d", &people_per_table);
    Like CommonTater said, remove the '\n'. And also..
    1. the first scanf is waiting for input.
    2. You type "50 30\n"
    3. the first scanf assigns 50 to length_of_room
    4. ' ' (space character) doesn't match ','. width_of_room is unchanged, 30 remains in the input stream
    5. the second scanf assigns 30 to length_of_table
    6. '\n' doesn't match ','. width_of_table is unchanged. input stream is now empty.
    7. the third scanf is waiting for input.


    Moral of the story; The format strings and the input has to match.

  13. #43
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by _Mike View Post
    Like CommonTater said, remove the '\n'. And also..
    1. the first scanf is waiting for input.
    2. You type "50 30\n"
    3. the first scanf assigns 50 to length_of_room
    4. ' ' (space character) doesn't match ','. width_of_room is unchanged, 30 remains in the input stream
    5. the second scanf assigns 30 to length_of_table
    6. '\n' doesn't match ','. width_of_table is unchanged. input stream is now empty.
    7. the third scanf is waiting for input.


    Moral of the story; The format strings and the input has to match.
    Nice catch on the commas guys... my bad for missing it. Sorry.

  14. #44
    Registered User
    Join Date
    Sep 2011
    Posts
    56
    thank you so much, I got the program fixed and running. You're helped means a lot to me everyone who answered. I might have couple questions later on, but I got problem A down, B is about the same.

    Thanks CommonTater

  15. #45
    Registered User
    Join Date
    Sep 2011
    Posts
    56
    can any of you guys help me out on the the formula for problem C.

Page 3 of 4 FirstFirst 1234 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Program solution needed...
    By vijay.neo in forum C Programming
    Replies: 6
    Last Post: 10-18-2006, 11:12 PM
  2. Some help needed with program.
    By ajdspud in forum C++ Programming
    Replies: 2
    Last Post: 12-06-2005, 02:36 PM
  3. Help needed with program.
    By ajdspud in forum C++ Programming
    Replies: 6
    Last Post: 11-22-2005, 03:05 PM
  4. Program crashes...help Needed!!
    By butterfly in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2002, 11:22 AM
  5. redirection program help needed??
    By Unregistered in forum Linux Programming
    Replies: 0
    Last Post: 04-17-2002, 05:50 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21