Like Tree1Likes
  • 1 Post By CommonTater

metro ticketing

This is a discussion on metro ticketing within the C Programming forums, part of the General Programming Boards category; I was given an assignment but I don't know much about c programming. please i will like to know more ...

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

    metro ticketing

    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
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Click this --> Homework Policy

    Now here's how you get around it...
    Actually do the work. Start writing the code on your own, get as far as you can.
    Then if you get stuck (really stuck, not lazy stuck) post the code you have, ask specific questions, and mabye we can help.
    mikel360 likes this.

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

    code:

    Code:
    #include <stdio.h>
    
    
    int main() {
        char *stations[10]={"Ashford","Brentworth","Canonbury Cross","Dowgate","Edbury","Fenchurch Street","Gresham","Hampstead","Islington","Jamaica Road"};
        int continueFlag=1;
        int canDo =1;
    	char* dStation = malloc(sizeof(char));
    	char* aStation  =malloc(sizeof(char));
    	int  journey    =1;
    	int  price      =0;
        printf("********************************************************************************\n");
        printf("*Usage:Input departure station name,arrival station name,single or return journey.\n");
        printf("*Each station name is its first letter, 0 for single journey,1 for return journy. \n");
        printf("*Example: A single ticket from Ashford to Edbury,the user can input ae0 or AE0   \n");
        printf("*Press quit to close program                                                     \n");
        printf("*Stations :{Ashford、Brentworth、Canonbury Cross、Dowgate、Edbury、             \n");
        printf("*           Fenchurch Street、Gresham、Hampstead、Islington、Jamaica Road}      \n");
        printf("******************************************************************************** \n");
    
       while (continueFlag) {
       fflush(stdin);
       int retVal = scanf("%c%c%d",dStation,aStation,&journey);
       if (retVal==3) {
           if (isStationExist(*dStation)==0){
              canDo=0;
              printf("%c is not right station name \n",*dStation);
            }
            if (isStationExist(*aStation)==0) {
              canDo=0;
              printf("%c is not right station name \n",*aStation);
            }
            if (isTicketType(journey)==-1) {
              canDo=0;
              printf("%d is not right ticket type. 0 for single 1 for return\n",journey);
            }
        	int startIndex = getStationIndex(dStation);
        	int endIndex   = getStationIndex(aStation);
            if(canDo) {
                if (journey) {
                   price = abs(endIndex-startIndex)*returnPrice;
                } else {
                   price = abs(endIndex-startIndex)*singlePrice;
                }
            	char* tickType[2]={"single","return"};
                printf("the %s price of station between %s and %s is ♀%d \n",*(tickType+journey),*(stations+startIndex),*(stations+endIndex),price);
           } else {
                printf("error input,please try again \n");
                canDo=1;
            }
        }
        else  {
          if (*dStation=='q') {
    	     continueFlag=0;
          } else {
            printf("error input,please try again \n");
          }
        }
       }
       free(aStation);
       free(dStation);
       return 0;
    }
    
    please someone help me with this

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    You wrote this in half an hour?

    First message... "I'm stumped, can anyone help me with this..."
    (I go to kitchen, make coffee and come back...)
    Second message... Complete program.

    So, where'd you copy it from?

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,516

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Oh my...

    I wonder what part of "Actually do the work" our friend doesn't understand?

  7. #7
    Registered User
    Join Date
    Feb 2011
    Posts
    10
    Actually I have the code but I didnt knw how to post the code, i have to read the error sign and tried to understand it, sorry it took so long

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 08-25-2010, 08:04 AM
  2. simple ticketing machine program
    By ryanmk91 in forum C Programming
    Replies: 5
    Last Post: 03-24-2010, 09:42 AM

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