Thread: Train simulation

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    10

    Unhappy Train simulation

    I was given an assignment but I don't know much about c programming. please i will like to know more that's the reason I have decided to join this forum.

    A new metro system is to be constructed by an independent company somewhere in the UK to link up 10 stations in a line (not a loop). The name of the station s are as follows:-
    Ashford - Brentworth - Canonbury Cross - Dowgate - Edbury - Fenchurch Street - Gresham - Hampstead - Islington - Jamaica Road

    The distance between each of the stations is fairly equal therefore the ticket cost between each station is £2.00 with an extra 50% added on for a return journey.

    Example: A return ticket from brentworth to hampstead will cost £18.00

    The company would like a user friendly piece of software to operate their ticket machines. All that is required at this stage is that the software does the following:-
    1. The user can select a departure station
    2. The user can select an arrival station
    3. the user can select either single or return journey.

    The program must then display on the screen a suitable summary of the ticket that the user can check prior to accepting and and paying.



    please can anyone help me out with this? I will really appreciate your feedback or comment(s)

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Welcome to the forum, mikel360

    You need to put together a start for your program, and then we can assist in some concrete way.

    You'll need a menu. Something like this function, but with different options and such, of course.

    Same basic logic. Main() calls menu(), menu calls everything else (or close to it).

    Code:
    int menu (void)
    {
      double avg_score; .
      int choice, scores[SIZE], hi_score, lo_score;
      get_score(scores);
    
      do {
            printf("\nMENU:");
            printf("\nMenu option one    1");
            printf("\nMenu option two    2");
            printf("\nMenu option three  3");
            printf("\nQUIT enter         4");
            printf("\nEnter your choice: ");
            scanf("%d", &choice);
            (void) getchar(); //clean the input of newline char
    
            switch (choice) {
            case 1: //your code might call many other functions here
              break;
            case 2: //to handle all these possible choices
              break;
            case 3: //your code here
              break;
            case 4: //your code here
              break;
            default:
              printf("Error! Try again please\n");
            }
      }while(choice != 4);
    
      return 0; //or (0)
    }
    Last edited by Adak; 02-24-2011 at 06:45 AM.

  3. #3
    Novice
    Join Date
    Jul 2009
    Posts
    568
    No code, no feedback.
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Decide how the user will enter in the station names. Likely not typing them in but rather by a menu choice, numeric... Then devise a calculation based on departure & arrival station number plus calculation for return trip.

  5. #5
    Registered User
    Join Date
    Feb 2011
    Posts
    10
    thank you guys for your feedback. I will post my code soon

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fork, execv, spawn, or something else?
    By DavidP in forum C++ Programming
    Replies: 8
    Last Post: 01-26-2009, 04:25 PM
  2. Role of c++ in simulation software
    By CChakra in forum C++ Programming
    Replies: 9
    Last Post: 11-18-2008, 02:36 AM
  3. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  4. Help with time simulation assignment
    By rakan in forum C++ Programming
    Replies: 3
    Last Post: 10-31-2006, 11:39 AM
  5. Boom, Headoshot!!
    By mrafcho001 in forum A Brief History of Cprogramming.com
    Replies: 50
    Last Post: 07-21-2005, 08:28 PM