Skip to content

Instantly share code, notes, and snippets.

@CSaratakij
Last active February 26, 2016 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CSaratakij/58d4c44b2897b76420e2 to your computer and use it in GitHub Desktop.
Save CSaratakij/58d4c44b2897b76420e2 to your computer and use it in GitHub Desktop.
ตัวอย่าง program ที่ run ได้ -> original ref : http://pantip.com/topic/34834020
#include<stdio.h>
#include<conio.h>
#include<stdbool.h>
int main()
{
char menu;
int recieved, change, stationPrice;
do
{
system("cls");
printf (" # THAILAND STATION # \n");
printf (" 1. Trang = 25 $ \n");
printf (" 2. BKK = 30 $ \n");
printf (" 3. Chumporn = 35 $ \n");
printf (" 4. Chiangmai = 40 $ \n");
printf("\n");
printf("Please select station \n");
printf ("------------------------ \n");
printf ("You choose station : ");
menu = getche();
switch(menu)
{
case '1':
stationPrice = 25;
printf(" Trang \n");
printf(" PRICE 25 $ \n");
do {
printf(" You pay : ");
scanf("%d", &recieved);
change = recieved-stationPrice;
if (change < 0) {
printf("\n");
printf("########################################## \n");
printf("You cannot buy this station \n");
printf("Please pay at least %d $ \n", stationPrice);
printf("########################################## \n");
printf("\n");
}
} while (change < 0);
printf(" Change = %d \n", change);
printf("Thank you for buying^_^ \n");
break;
case '2':
stationPrice = 30;
printf(" BKK \n");
printf(" PRICE 30 $ \n");
do {
printf(" You pay : ");
scanf("%d", &recieved);
change = recieved-stationPrice;
if (change < 0) {
printf("\n");
printf("########################################## \n");
printf("You cannot buy this station \n");
printf("Please pay at least %d $ \n", stationPrice);
printf("########################################## \n");
printf("\n");
}
} while (change < 0);
printf(" Change = %d \n", change);
printf("Thank you for buying^_^ \n");
break;
case '3':
stationPrice = 35;
printf(" Chumporn \n");
printf(" PRICE 35 $ \n");
do {
printf(" You pay : ");
scanf("%d", &recieved);
change = recieved-stationPrice;
if (change < 0) {
printf("\n");
printf("########################################## \n");
printf("You cannot buy this station \n");
printf("Please pay at least %d $ \n", stationPrice);
printf("########################################## \n");
printf("\n");
}
} while (change < 0);
printf(" Change = %d \n", change);
printf("Thank you for buying^_^ \n");
break;
case '4':
stationPrice = 40;
printf(" Chiangmai \n");
printf(" PRICE 40 $ \n");
do {
printf(" You pay : ");
scanf("%d", &recieved);
change = recieved-stationPrice;
if (change < 0) {
printf("\n");
printf("########################################## \n");
printf("You cannot buy this station \n");
printf("Please pay at least %d $ \n", stationPrice);
printf("########################################## \n");
printf("\n");
}
} while (change < 0);
printf(" Change = %d \n", change);
printf("Thank you for buying^_^ \n");
break;
default :
printf("\n No station %c has found. \n", menu);
break;
}
printf("\n");
printf("Press 'Enter' to re-select the station. \n");
printf("Press 'q' to quit. \n");
char userChoice = getch();
if (userChoice == 'q') {
printf("\n^_^ See you later ^_^");
getche();
return 0;
}
} while(true);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment