Very basic program - In need of help

This is a discussion on Very basic program - In need of help within the C Programming forums, part of the General Programming Boards category; Hi, I was wondering if someone could help me create a program. I am new to C and I want ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    6

    Unhappy Very basic program - In need of help

    Hi, I was wondering if someone could help me create a program.

    I am new to C and I want to create the following program.

    Create a simple seat booking program for a 10 seater passenger aircraft. The seats are numbered 1 - 10 of which 1 - 5 are in a smoking section of the plane and 6 - 10 are in the non smoking section.

    The user should be prompted

    Please type 1 for SMOKING
    Please type 2 for NON-SMOKING

    On entering 1 or 2, a seat should be allocated to the passenger and a boarding pass printed on the screen. The boarding pass must include the seat number and whether the passenger is in the smoking or non-smoking area.

    No seat should be booked more than once.

    If a request is made for a seat in the smoking area and there are no available seats then the user should be prompted "Are you willing to sit in the NON-SMOKING section (Y/N?)"

    If the answer is Y then a non-smoking seat will be allocated and a boarding pass printed. If the answer is N then the user is told "OK, next flight is in 3 hours"

    If a seat in the non-smoking area is requested and there are no available seats then similar action should be taken to what is above.
    I use Dev C++ and I have created 5 very basic programs in C. Can someone please create this program for me and paste the code here (or PM me it) so I can put the code into Dev C++ and learn from it.

    I am sure most people here can create this program in 5 minutes tops, but it would take me weeks to do this. I can only do the first 2 printf statements and then I am lost so please help if you can.

    Thanks all

  2. #2
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    Em... No?

    Your intentions are noble, but still this isn't RENT-A-CODER, most
    people don't have the time to write programs for others. What
    we would do however, is if you made an attempt at this, or if
    you have specific questions about how to proceed, we could help.
    The best way to learn is from your mistakes, but if you need some
    sample code to get you learning something, then try the local
    tutorials here. Other than that, there's not much anybody will do
    for you.

    One tip though, do you want to fill the seats in each section
    sequentially (as in 1 through to 5) or randomly? You will need
    the rand function to make random selections, but bear in mind
    you would have to check for repititions. Here's a link on rand()
    Personally I'd do it sequentially first, but then develop it and do it
    randomly for extra experience and challenge - the choice is yours.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  3. #3
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,834
    Code:
    int smokingSeatIsOccupied[5] = { 0 };
    int nonsmokingSeatIsOccupied[5] = { 0 };
    Write some code to search (using say a for loop) to determine if a seat is occupied.

    Post what you can manage from these hints...
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    6
    OK, I've made an attempt at this but to be honest, I am really lost and I am getting frustrated.

    I have uploaded my program to my webspace. The program is in a zip folder and inside are both the code file and exe file. Can someone help me complete the array please?

    http://homepage.ntlworld.com/stephan...eatBooking.zip

    When it asks you to press 1 for smoking, one of the seats (between 1 - 5) should say next to it "booked" instead of the default "0" you see at the moment. If you press 2, one of the seats (between 6 - 10) should be booked.

    That is the next step, so can someone please explain how I would do this? I have tried reading a C book and editing the code but I am completely lost!

    Thanks so much for any help

  6. #6
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    I think that it's good you tried and came back - however this is a
    pretty basic program so rather than give you the answers I'll
    point you in the direction of what you will need to know and how
    to structure the program and teach yourself how to do it.

    Here goes - all links taken from the tutorials at this site:

    If Statements - study these in detail
    Loops - particularly the for loop - useful with arrays
    Functions - learn about passing arguments and returning values

    If you read the above articles, you should learn some skills which
    will help you in the program.

    Here's what you need your program to do:

    1) Program starts - should ask the user to enter a choice - 1 for
    smoking, 2 for non - smoking
    2) pass this choice to a function. Use an if statement to
    decide which part of the plane you want to look at
    3) having done the above, use a for loop to print out details of
    the seats occupied - use an if statement to check if each element
    (seat) in you array is set to 0 - if it is, print out that it is free -
    if not, print out that it is booked
    4) Now the user should be given a choice to book a seat - they
    enter a number to indicate their choice
    5) pass this number to a function - this function should use an
    if statement to check if that seat is free (has a 0 stored at that
    element) or is booked (has a 1, or some other value stored
    at that element). If it is free - set it to 1 - if not, print that the
    seat has been booked.

    That is basically the task you have set for yourself, with all the
    main steps flagged - what you have done is similar to steps
    1 - 3, but they can be done with a better approach by leaving
    the program doing the work using loops - also it can be achieved
    using 1 function as opposed to your current approach using 2.
    (HINT passing the choice to a function that can print out details
    for both sections of the plane)

    Just take it all one step at a time - If statements are very much
    the key to doing a program like this IMO. Take it slow and
    come back if you run into problems
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  7. #7
    Registered User
    Join Date
    Mar 2005
    Posts
    37
    Quote Originally Posted by gohan2091
    OK, I've made an attempt at this but to be honest, I am really lost and I am getting frustrated.
    Gohan.. Getting frustrated.. won't get you anywhere.
    The reason people come here .. "message board ".. 'cos they are lost.. or are looking for challenging problem....

    There are lots of people who are ready to help you to learning C .. and not to do your piece of code. .. :-)
    ( only if you make a honest attempt ) and more over.. I suggest you to post question.. as to where you are stuck and where you need help rather than posting the complete question and expecting someone to do it for you ..!!

    I just saw a signature from DWK ( a member )

    "The only real mistake is the one from which we learn nothing."
    -- John Powell

    Make as many mistake.. as you can.. or else u won't learn.. !!

  8. #8
    Registered User
    Join Date
    May 2006
    Posts
    6

    Red face

    Quote Originally Posted by Richie T
    I think that it's good you tried and came back - however this is a
    pretty basic program so rather than give you the answers I'll
    point you in the direction of what you will need to know and how
    to structure the program and teach yourself how to do it.

    Here goes - all links taken from the tutorials at this site:

    If Statements - study these in detail
    Loops - particularly the for loop - useful with arrays
    Functions - learn about passing arguments and returning values

    If you read the above articles, you should learn some skills which
    will help you in the program.

    Here's what you need your program to do:

    1) Program starts - should ask the user to enter a choice - 1 for
    smoking, 2 for non - smoking
    2) pass this choice to a function. Use an if statement to
    decide which part of the plane you want to look at
    3) having done the above, use a for loop to print out details of
    the seats occupied - use an if statement to check if each element
    (seat) in you array is set to 0 - if it is, print out that it is free -
    if not, print out that it is booked
    4) Now the user should be given a choice to book a seat - they
    enter a number to indicate their choice
    5) pass this number to a function - this function should use an
    if statement to check if that seat is free (has a 0 stored at that
    element) or is booked (has a 1, or some other value stored
    at that element). If it is free - set it to 1 - if not, print that the
    seat has been booked.

    That is basically the task you have set for yourself, with all the
    main steps flagged - what you have done is similar to steps
    1 - 3, but they can be done with a better approach by leaving
    the program doing the work using loops - also it can be achieved
    using 1 function as opposed to your current approach using 2.
    (HINT passing the choice to a function that can print out details
    for both sections of the plane)

    Just take it all one step at a time - If statements are very much
    the key to doing a program like this IMO. Take it slow and
    come back if you run into problems

    Thanks so much for your reply, I appericate it very much.

    Your 5 steps make a lot of sense but I am finding it hard to even set up an if statement (because I used a switch statement)
    I am getting really frustrated and stressed over this program, I have read the links you gave me but I cannot implement it into my program. My understanding of C is poor and all I am doing at the moment is stressing out.

    Obviously I need some sort of loop in my first function but I am not sure how I would implement a loop in a function. I dont know what sort of loop I need, or what my loop would say or where I would put the loop.

    Richie, do you have MSN Messenger? This may sound stupid but could you talk to me on there? At least that is live and it is much better than speaking over the forum. You understand what I have to do but I just cant write the code for it, I keep getting errors and I am confused with what part of my code to keep and what to delete.

    This may be asking too much but could you talk to me on MSN Messenger sometime and we make the program together? You help me write the code and explain it to me line by line, then I can understand it. This is the best way I learn. I learnt photoshop from a mate who explained it peice by peice. I'm sure it wont take long as this is a simple program to make.

    My MSN email is <<snipped>>

    Thanks
    Last edited by Salem; 05-31-2006 at 12:17 PM. Reason: Remove email address

  9. #9
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    My understanding of C is poor
    Then you should consider stepping back a notch and get to know C better first.


    My MSN email is gohan2091 at hotmail dot com
    ... and the spambots will pick it up in 27 minutes, 46 seconds from now. We have forums. Nobody is gonna add you. Honest.



    Nobody is gonna write the code for you. No matter how nicely you phrase it. No matter how much you convince us you've "tried". It's your code, write it yourself.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  10. #10
    ex-DECcie
    Join Date
    Dec 2005
    Posts
    125

    C'mon, give it a try.....

    Instead of trying to get other to do it for you, you'll have more luck if you put forth an effort, however feeble you feel it might be, and post your code here.

    We're more than willing to disect what you come up with, but no one here is going to do it for you....
    Mr. Blonde: You ever listen to K-Billy's "Super Sounds of the Seventies" weekend? It's my personal favorite.

  11. #11
    Registered User
    Join Date
    May 2006
    Posts
    6
    Thanks for the replies. I did manage to get someone to help me, he was very polite and he helped me alot on MSN, he was also from this forum so a big thanks to him. My program is coming along better now, if I run into any more problems, I will ask on here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  2. Basic encryption program???
    By Finchie_88 in forum C++ Programming
    Replies: 14
    Last Post: 09-10-2004, 10:01 AM
  3. IDEA: A basic drawing program
    By ygfperson in forum Contests Board
    Replies: 0
    Last Post: 08-13-2002, 12:15 AM
  4. Replies: 2
    Last Post: 05-10-2002, 05:16 PM
  5. Help me with this basic c program
    By [ToXiC]-[LeaK] in forum C Programming
    Replies: 1
    Last Post: 01-28-2002, 11:44 PM

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