Thread: Help with forming addresses.

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    7

    Question Help with forming addresses.

    Hi. I am new to c++ and found this site very usefull for solving a switch problem the other day. But being new to programming i have come accross another problem and would apreciate some help with it. I've included the small part of the program i have so far. I still have a lot to do but am stuck on this part. The user picks a choice of train station then picks another train station from the same list. I have succesfully set it up so a choice can be made and then the next choice using one switch statement but when i try to show the two choices in the line //Show summary of chosen stations, i cannot get it to show the station names, only some symbols.I have got the station choice numbers in 'leaving' and 'arriving' which i need to use later on for the prices and things but i also need the station names sepeartelly in an address that i can access for when i bring up a summary of the ticket. What i have so far is:

    Code:
    int main(int argc, char *argv[])
    {
        int leaving, arriving, choice1, choice2;
        char stationsswitch(int);
    
                
                                                         
               printf("\nEnter the station you will be leaving from by \nentering the corresponding number from the list below");
               printf("\n 1 = Ashford\n 2 = Brentworth\n 3 = Canonbury Cross\n 4 = Dowgate\n 5 = Edbury\n");
               printf(" 6 = Fenchurch Street\n 7 = Gresham\n 8 = Hampstead\n 9 = Islington\n 10 = Jamaica Road\n");
               scanf ("%d", &leaving);                       //Put number in leaving
               choice1 = stationsswitch(leaving);             //Use function to pick station using leaving choice number
    
              printf(" as your leaving station\n");                //show chosen station
                      
              
              
              printf("\nEnter the station you will be arriving at by \nentering the corresponding number from the list below");
              printf("\n 1 = Ashford\n 2 = Brentworth\n 3 = Canonbury Cross\n 4 = Dowgate\n 5 = Edbury\n");
               printf(" 6 = Fenchurch Street\n 7 = Gresham\n 8 = Hampstead\n 9 = Islington\n 10 = Jamaica Road\n");
              scanf("%d", &arriving);                         //Put number in arriving
              choice2 = stationsswitch(arriving);            //Use function to pick station using arriving choice number
              
              printf(" as your arriving station.\n\n");                    //show chosen station
              
              
              printf("You have selected %c and %c as your stations\n\n", choice1, choice2);  //Show summary of chosen stations
              
              
      system("PAUSE");	
      return 0;
    }
    
    
    char stationsswitch(int choice1)           //Function for deciding station choice
    {
         
         switch (choice1)
              {
                     case 1:
                          system ("CLS");
                          printf("You have selected Ashford ");
                          break;
                     case 2:
                          system ("CLS"); 
                          printf("You have selected Canonbury Cross ");
                          break;
                     case 3:
                          system ("CLS");
                          printf("\nYou have selected Canonbury Cross ");
                          break;
                     case 4:
                          system ("CLS");
                          printf("\nYou have selected Dowgate ");
                          break;
                     case 5:
                          system ("CLS");
                          printf("\nYou have selected Edbury ");
                          break;
                     case 6:
                          system ("CLS");
                          printf("\nYou have selected Fenchurch Street ");
                          break;
                     case 7:
                          system ("CLS");
                          printf("\nYou have selected Gresham ");
                          break;
                     case 8:
                          system ("CLS");
                          printf("\nYou have selected Hampstead ");
                          break;
                     case 9:
                          system ("CLS");
                          printf("\nYou have selected Islington ");
                          break;
                     case 10:
                          system ("CLS");
                          printf("\nYou have selected Jamaica Road ");
                          break;
                     
              }
    
    }
    I have tried putting the station names into an address within the switch statement but i cant get it working. If someone could help it would be very appreciated.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Not sure why this has appeared in the C++ section, but: %c prints a character. If you want to print a word, don't use %c (%s sounds like a good bet). On the same token: 1 is not a word. You will need to have the strings somewhere, if you want to print something other than 1 for station number 1.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Numeric addresses for computers
    By great in forum C Programming
    Replies: 4
    Last Post: 08-23-2010, 11:53 AM
  2. Working with memory addresses
    By Fujy in forum C++ Programming
    Replies: 7
    Last Post: 01-18-2010, 09:31 AM
  3. Addresses and extracting the value stored at an address
    By donoe_85 in forum C Programming
    Replies: 4
    Last Post: 04-08-2009, 03:38 AM
  4. Addresses and pointers help...
    By GCNDoug in forum C Programming
    Replies: 13
    Last Post: 04-07-2007, 05:37 PM
  5. how can know in memory someone addresses in free list
    By 0000000009 in forum C Programming
    Replies: 8
    Last Post: 10-17-2005, 12:35 AM