Hi everyone. Could someone please help me with this. I have a program which i have written and finished for a college assignment. It is completely done. I have a perfect working copy on my laptop but when i copy it to usb stick and take it to college it decides not to work. Its driving me crazy because the code works!! It happens at the part when it asks wether you want a return or not. The do while loop should work fine and it does at home. But when transfered to colege it just freezes at that point and whatever you input, letter or number, it just keeps looping. Its so anoying as i have it working. I know it should probably be %c instead of %s but for some reason it works that way and i have tried changing this among other things and it still doesn't work.
If anyone can help it would be really apreciated.
Thanks everyone :)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
int y, n, leaving, arriving, ret, check, price;
do { //Do while loop for whole program
do{ //Do while loop for leaving station choice
printf("\n\n ########## Welcome to the ticket machine ########## \n\n"); //Welcome message
printf("\n Please select a leaving station from the list below\n");
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", &leaving);
system ("CLS");
} while (leaving <1 || leaving >10);
do { //Do while loop for arriving station choice
printf("\n\n ########## Welcome to the ticket machine ########## \n\n");
printf("\n Please select an arriving station from the list below\n ");
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);
system ("CLS");
} while (arriving <1 || arriving >10);
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 y or n are not selected
do { //Do while loop for ticket summary
system ("CLS"); //Clear screen for ticket summary
//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");
switch (arriving)
{
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 arriving station.\n\n");
if (ret == 'y') //Print summary of return choice
{
printf("\n You have selected a return ticket\n\n"); //Show if return has been chosen
}
else if (ret == 'n')
{
printf("\n You have not selected a return ticket\n\n"); //Show if return has not been chosen
}
//END OF TICKET SUMMARY
printf("\n\n\n Are these the correct options for your ticket?\n\n"); //Show summary of choices made
printf(" Press y if they are correct.\n Press n if you want to make your selections again:\n");
scanf("%s", &check);
if (check != 'y' && check != 'n')
{
system ("CLS"); //Clear screen if not selected y or n
}
if (check == 'y')
{
system ("CLS");
printf("\n\n Your selections have been saved.\n\n"); //Show if choices are confirmed
}
else if (check == 'n')
{
system ("CLS");
printf("\n\n Your selections have been cleared.\n Please make your choices again.\n\n");
}
} while (check != 'y' && check != 'n'); //End of loop for ticket summary
} while (check != 'y'); //End of loop for whole choices selection program
//Pricing part
if (leaving > arriving) //If leaving greater than arriving then subtract arriving
{
price = leaving*2 - arriving*2;
}
else
{ //Else subtract leaving from arriving
price = arriving*2 - leaving*2;
}
if (ret == 'y') //If return was picked times ticket by 1 and half
{price = price*1.5;}
printf("\n\n Your ticket price is : "); //Show ticket price
printf(" %c %d \n\n", 156, price);
printf(" Please make payment and collect ticket.\n\n");
system("PAUSE");
return 0;
}