hi. this is my program for bus ticket detail. at the bottom of my program, i want user to input yes or no for loop this program. but before i can input anything, it already told me that 'Please input the correct answer'. it is like i already input something. how to overcome this?
and 1 more question, is it possible to put seat number in this program so when the program loop and same seat number is chose i want to the program to tell that the seat is occupied. thank you very much :)
#include <stdio.h>
int main ()
{
int type, desti, time, amount;
char* bus;
char* dest;
char yn;
int time2;
double price, tprice;
do {
printf ("------------------------------\n");
printf ("| Speed of Light Bus Company |\n");
printf ("------------------------------\n\n");
printf ("------------------------------------------------| \n");
printf (" |Please select your preferred type of bus | \n");
printf (" |1. Single-decker\t\t\t |\n");
printf (" |2. Double-decker\t\t\t |\n");
printf ("------------------------------------------------| \n\n");
do { printf (" >> ");
scanf ("%d", &type);
if (type == 1)
printf ("\n >> You've selected single-decker type\n\n");
else if (type == 2)
printf ("\n >> You've selected double-decker type\n\n");
else
printf ("\n - Please enter the correct number");
} while (type > 2);
if (type == 1)
bus = "Single-decker\0";
else
bus = "Double-decker\0";
printf ("-------------------------------------| \n");
printf (" |Please choose your destination| \n");
printf (" |1. Taiping >> RM28.30\t\t|\n");
printf (" |2. Pulau Pinang >> RM31.20\t|\n");
printf (" |3. Kuala Lumpur >> RM33.80\t|\n");
printf (" |4. Alor Setar >> RM36.80\t|\n");
printf (" |5. Kuantan >> RM16.30\t\t|\n");
printf (" |6. Seremban >> RM27.40\t|\n");
printf (" |7. Melaka >> RM39.50\t\t|\n");
printf (" |8. Johor Bharu >> RM32.10\t|\n");
printf ("-------------------------------------| \n\n");
do { printf (" >> ");
scanf ("%d", &desti);
if (desti == 1) {
printf ("\nYou've selected --> Taiping >> RM28.30\n");
dest = "Taiping\0";
price = 28.30; }
else if (desti == 2) {
printf ("\nYou've selected --> Pulau Pinang >> RM31.20\n");
dest = "Pulau Pinang\0";
price = 31.20; }
else if (desti == 3) {
printf ("\nYou've selected --> Kuala Lumpur >> RM33.80\n");
dest = "Kuala Lumpur\0";
price = 33.80; }
else if (desti == 4) {
printf ("\nYou've selected --> Alor Setar >> RM36.80\n");
dest = "Alor Setar\0";
price = 36.80; }
else if (desti == 5) {
printf ("\nYou've selected --> Kuantan >> RM16.30\n");
dest = "Kuantan\0";
price = 16.30; }
else if (desti == 6) {
printf ("\nYou've selected --> Seremban >> RM27.40\n");
dest = "Seremban\0";
price = 27.40; }
else if (desti == 7) {
printf ("\nYou've selected --> Melaka >> RM39.50\n");
dest = "Melaka\0";
price = 39.50; }
else if (desti == 8) {
printf ("\nYou've selected --> Johor Bharu >> RM32.10\n");
dest = "Johor Bharu\0";
price = 32.10; }
else
printf ("\n - Please enter the correct number");
} while ( desti > 8);
printf ("\nPlease enter how many ticket you want >> ");
scanf ("%d", &amount);
tprice = price * amount;
printf ("--------------------------------------| \n");
printf (" |Please choose what time you want | \n");
printf (" |1. 1030\t\t\t |\n");
printf (" |2. 1430\t\t\t |\n");
printf (" |3. 1800\t\t\t |\n");
printf (" |4. 2230\t\t\t |\n");
printf ("--------------------------------------| \n\n");
do { printf (" >> ");
scanf ("%d", &time);
if (time == 1)
time2 = 1030;
else if (time == 2)
time2 = 1430;
else if (time == 3)
time2 = 1800;
else if (time == 4)
time2 = 2230;
else
printf ("\n - Please enter the correct number");
} while ( time > 4);
printf ("\nThis is your ticket information : \n");
printf ("Bus type : %s\n", bus);
printf ("Destination : %s\n", dest);
printf ("Total price = %0.2f \n", tprice);
printf ("Time : %d\n", time2);
printf ("\nDo you want to print another ticket? (Y/N)\n");
do { printf (" >> ");
scanf ("%c", &yn);
if ( yn == 'Y' || yn == 'y' || yn == 'N' || yn == 'n' ) {
break;
}
else {
printf ("\nPlease enter the correct answer"); }
} while (yn != 'Y' || yn != 'y' || yn != 'N' || yn != 'n');
} while (yn == 'Y' || yn == 'y');
}