help with do-while loop!!
Hi. I have nearly finished a program i am writimg but am having trouble with the last thing i need to put in. All it is, is a do while loop that will loop that part of the program until the correct input has been entered. Which means the user cant enter a letter instead of a number or the wrong number. But for some reason it doesn't want to work. I have various other do while loops in the program and they all work fine. I also use the choice made to return a statement from the switch statement later in the program as you can see.
The ones that aren't working are the one's for the first two choices that are made. I tried making a do while loop that would repeat until a number from 1 to 10 was entered which worked fine when entering other numbers apart from 1 to 10 but when i enter a letter it just freezes and the program flickers. I also tried changing it so it asked for a letter from a to j instead but when putting a do while loop that repeated until a letter from a to j was input it really didn't like it. Can anyone help? it would be much appreciated. I have put a segment of the prgram in so you can see what i have so far. I have left in my attempt at the do while loop for the first selection bit ( commented as NOT WORKING!!! ).
Many thanks everyone.
Code:
do { //do loop for whole program if ticket is correct after ticket summary
do { //NOT WORKING!!!
printf("\n\n ########## Welcome to the ticket machine ########## \n\n"); //welcome message
printf("\n Please select a leaving station from the list below\n"); //leaving station choice
printf(" by entering the corresponding number :\n");
printf("\n 1 = Ashford \n 2 = Brentworth \n 3 = Canonbury Cross \n 4 = Dowgate \n 5 = Edbury \n 6 = Fenchurch Street \n");
printf(" 7 = Gresham \n 8 = Hampstead \n 9 = Islington \n 10 = Jamaica Road \n");
scanf("%d", &leaving); //put leaving station choice in &leaving
system ("CLS");
} while (leaving != 1,2,3,4,5,6,7,8,9,10); //NOT WORKING!!!
printf("\n\n ########## Welcome to the ticket machine ########## \n\n");
printf("\n Please select an arriving station from the list below\n "); //arriving station choice
printf(" by entering the corresponding number :\n");
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 arriving station choice into &arriving
system ("CLS");
do //do while loop for return ticket choice
{
system("CLS");
printf("\n\n ########## Welcome to the ticket machine ########## \n\n\n");
printf("\n Do you require a return ticket?");
printf("\n\n Press y for a return ticket.\n");
printf(" Press n if a return ticket is not required:\n");
scanf("%s", &ret); //assign return choice to &ret
}
while (ret != 'y' && ret != 'n'); //keep looping if r or x are not selected
do { //start of loop for ticket summary
system ("CLS"); //clear screen for ticket summary
//START OF TICKET SUMMARY
printf("\n ##### TICKET SUMMARY #####\n\n\n"); //ticket summary message
switch (leaving)
{
case 1:
printf("\n You have selected Ashford ");
break;
case 2:
printf("\n You have selected Brentworth ");
break;
case 3:
printf("\n You have selected Canonbury Cross ");
break;
case 4:
printf("\n You have selected Dowgate ");
break;
case 5:
printf("\n You have selected Edbury ");
break;
case 6:
printf("\n You have selected Fenchurch Street ");
break;
case 7:
printf("\n You have selected Gresham ");
break;
case 8:
printf("\n You have selected Hampstead ");
break;
case 9:
printf("\n You have selected Islington ");
break;
case 10:
printf("\n You have selected Jamaica Road ");
break;
}
printf("as your leaving station.\n\n");