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:
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.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; } }![]()



LinkBack URL
About LinkBacks



