Click here to Skip to main content
15,170,971 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#include<string.h>
#define name 20


struct detail
{
    int iway;
    int oneway;
    int twoway;
    int age;
    int id;
    int id2;
    char cname[name];
    char date[10];
    char date1[10];
    char itime[10];
    char itime2[10];
};

struct place
{
    int idestination;
    char jb[30];
    char pen[30];
    char ter[30];
    char lg[30];
};

void main()
{
    void booking(),check(),display(),cancel(),save();
    struct detail sdetail;
    struct place splace;
    char user,pass;
    char choice;

          printf("Enter username: ");
          scanf(" %s",&user);
          printf("\nEnter password:");
          scanf(" %s",&pass);
          system("cls");
	do
	{

		printf("\n\n\t\t ********************************************************************");
		printf("\n\t\t                  WELCOME TO DINS AIRLINES                            ");
		printf("\n\t\t   *******************************************************************");
		printf("\n\n\n\t\t Please enter your choice from below (1-5):");
		printf("\n\n\t\t 1. Booking");
		printf("\n\n\t\t 2. Check Schedule");
		printf("\n\n\t\t 3. DISPLAY RECORDS");
		printf("\n\n\t\t 4. Cancel");
		printf("\n\n\t\t 5. EXIT");
		printf("\n\n\t\t Enter your choose ");


		scanf("%d", &choice); fflush(stdin);
		system("cls");  //(cls" is a command on some operating systems that clears the screen

		switch (choice) // (Each value is called a case, and the variable being switched on is checked for each switch case)
		{
		case 1:
			booking();
            break;
		case 2:
			check();
			break;
		case 3:
			display();
			break;
        case 4:
            cancel();
            break;
		case 5:
		{
				  save();
				  break;
		}
		Default:
			printf("\n\n\t SORRY INVALID CHOICE!");
			printf("\n\n\t PLEASE CHOOSE FROM 1-5");
		}
		getch();

	} while (choice != 5);
}

void booking()
{
    struct detail sdetail;
    struct place splace;
    char user,pass,key;
    int choose,ticket;
    char proceed,choice,meals;
    int c,p,a,sum=0;
	int i;
	int j;
	int s[40]={};
    float pay=0,total_price;


        printf("1.KL - JOHOR BHARU\t\t\t\t 0830-0930\t 1400-1500\n");
        printf("2.KL - PENANG\t\t\t\t\t 0800-0900\t 1300-1400 \n");
        printf("3.KL - TERENGGANU\t\t\t\t 1000-1120\t 1700-1820 \n");
        printf("4.KL - LANGKAWI \t\t\t\t 0900-1015\t 1600-1715 ");

        printf("\nHow many ticket did you want? ");
        scanf("%d",&ticket);

        for(a=1;a<=ticket;a++){


        printf("\n---------------------BOOKING TICKET----------------------\n");
        printf("NAME: ");
        scanf(" %s",&sdetail.cname);
        strupr(sdetail.cname);
        printf("AGE: ");
        scanf(" %d",&sdetail.age);
        printf("PASSPORT ID: ");
        scanf(" %d",&sdetail.id);
        printf("\nCHOOSE YOUR DESTINATION: ");
        scanf(" %d",&splace.idestination);


    if(splace.idestination==1)
    {
        splace.idestination==splace.jb;
        //printf("KL - JOHOR BHARU");
    }
    else if(splace.idestination==2)
    {
        splace.idestination==splace.pen;
       // printf("KL - PENANG");
    }
    else if(splace.idestination==3)
    {
        splace.idestination==splace.ter;
       // printf("KL - TERENGGANU");
    }
    else if(splace.idestination==4)
    {
        splace.idestination==splace.lg;
       // printf("KL - LANGKAWI");
    }
     printf("\nCHOOSE YOUR WAY(1-ONE WAY,2-TWO WAY) :");
    scanf(" %d",&sdetail.iway);


    if (sdetail.iway==1)
    {
        sdetail.iway=sdetail.oneway;
         printf("\nDeparture date:");
        scanf(" %s",&sdetail.date);
        printf("\nDeparture TIME: ");
        scanf(" %s",&sdetail.itime);


                    if(splace.idestination == 1){
                        pay=130*1;
                        }
                else if(splace.idestination == 2){
                         pay=150*1;
                        }

                else if(splace.idestination == 3){
                         pay=170*1;
                        }

                else if(splace.idestination == 4){
                         pay=200*1;
                        }
    }
    else if(sdetail.iway==2)
    {
          sdetail.iway=sdetail.twoway;
          printf("\nDeparture date:");
          scanf(" %s",&sdetail.date);
          printf("\nDeparture TIME: ");
          scanf(" %s",&sdetail.itime);
          printf("\nReturn date:");
          scanf(" %s",&sdetail.date1);
          printf("\nReturn TIME: ");
          scanf(" %s",&sdetail.itime2);


                    if(splace.idestination == 1){
                         pay=130*2;
                        }

                else if(splace.idestination == 2){
                         pay=150*2;
                        }

                else if(splace.idestination == 3){
                         pay=170*2;

                        }

                else if(splace.idestination == 4){
                         pay=300*2;
                        }

    }
    else
    {
        printf("INVALID\n");
    }
    for (j=0; j<1; j++)
	{
		printf("\nChoose 1 for First Class and 2 for Economic class\t");
		scanf("%i",&c);

		switch(c)
		{
		case 1:
			printf("\nFirst class\n");
			printf("Seats available are 1-10.\n");

                printf("Pick a seat:\n\n");
                scanf("%i",&p);
                sum=100;
                s[j]=p;

			    for (i=0; i<j; i++)
			    {
                    if (s[j]==s[i])
                    {
                        printf("\n\nSeat taken.\n\n");
                        break;
                    }
			    }

            break;
		case 2:
			printf("\nEconomical class\n");
			printf("Seats available are 11-30.\n");

                printf("Pick a seat:\n\n");
                scanf("%i",&p);
                sum=50;
                s[j]=p;

			    for (i=0; i<j; i++)
			    {
                    if (s[j]==s[i])
                    {
                        printf("\n\nSeat taken.\n\n");
                        break;
                    }
			    }

            break;
        default:
                break;

		}
	}

	   printf("\nCHOOSE YOUR FREE MEAL :");
	   scanf(" %s",&meals);

	   switch(meals)
	    {
        case'A':
            printf("KFC");
            break;
        case'B':
            printf("MCD");
            break;
        case'C':
            printf("DOMINOS");
            break;
        default :
            break;

	    }

	     total_price=(pay+sum)*ticket;
}
}
void check()
{
        printf("1.KL - JOHOR BHARU\t\t\t\t 0830-0930\t 1400-1500\n");
        printf("2.KL - PENANG\t\t\t\t\t 0800-0900\t 1300-1400 \n");
        printf("3.KL - TERENGGANU\t\t\t\t 1000-1120\t 1700-1820 \n");
        printf("4.KL - LANGKAWI \t\t\t\t 0900-1015\t 1600-1715 ");
        return;
}
void display()
{

    struct detail sdetail;
    struct place splace;
    int p;


      system("cls");

       printf("\n===============================================================\n");
       printf("NAME : %s\n",sdetail.cname);
       printf("AGE : %d\n",sdetail.age);
       printf("PASSPORT ID : %d\n",sdetail.id);

        if(splace.idestination == 1){
                strcpy(splace.jb,"KL-JOHOR BHARU");
                printf("DESTINATION : %s\n",splace.jb);
                        }
         else if(splace.idestination == 2){
                strcpy(splace.pen,"KL-PENANG");
                printf("DESTINATION : %s\n",splace.pen);
                        }
            else if(splace.idestination == 3){
                strcpy(splace.ter,"KL-TERENGGANU");
                printf("DESTINATION : %s\n",splace.ter);
                        }
        else if(splace.idestination == 4){
                strcpy(splace.lg,"KL-LANGKAWI");
                printf("DESTINATION : %s\n",splace.lg);
                        }

       printf("SEAT : %d\n",p);
       printf("DEPARTURE DATE: %s\n",sdetail.date);
       printf("DEPARTURE TIME: %s\n",sdetail.itime);
       printf("RETURN DATE: %s\n",sdetail.date1);
       printf("RETUN TIME: %s\n",sdetail.itime2);
       printf("\n===============================================================\n");


       printf("\nPlease pay your ticket using online banking or master card.");
       printf("\nThank you for choosing our airlines.Enjoy your holiday!");
       return;
}

void cancel()
{
    struct detail sdetail;

    printf("Enter your PASSPORT ID: ");
    scanf("%d",sdetail.id2);

    if(sdetail.id2==sdetail.id)
    {
    printf("\nYour cancellation is successful.");
    }
    else
    {
        printf("\nYour cancellation is not successful.Sorry!");
    }
    return;

}

void save()
{
    float total_price;
    printf("TOTAL OVERALL : RM %.2f",total_price);
    printf("\nPlease pay your ticket using online banking or master card.");
    printf("\nThank you for choosing our airlines.Enjoy your holiday!");
    return;
}


What I have tried:

i have almost done my coding but i don't have any ideas to do in void display area. i think i want to use pointers but i don't know how to it.Can you help me?
Updated 22-Jan-21 5:03am
v2
Comments
CPallini 22-Jan-21 13:37pm
   
Actually your code doesn't compile. It gives many errors. I suppose you should first fix them and then try to do more. By the way, what you mean with "but i don't have any ideas to do in void display area. i think i want to use pointers but i don't know how to it"? I don't get you.

1 solution

So you just dump your code on us and expect us to have any idea what your code is meant to do, or what you might need help with?

And all you can say is "it might need pointers"? This smells a lot of homework, and the point of the homework is probably to get you to understand, use and gain some confidence in pointers - which are fundamental to the whole ay that C works, it's pretty much impossible to do anything non-trivial without them (and even trivial stuff probably needs them just to print anything other than numbers!)

So your understand of pointers is really, really important - and you only learn buy doing, not by getting someone else to do it and hoping you can work out how it works afterwards.

So, start here: A Beginner's Guide to Pointers[^] and use the debugger to find out what your code is doing when it runs on your attempt with pointers.
If it doesn't work and you can't find out why after some good work with the debugger, post just the relevant code fragments and explain what it does that you didn't expect, or doesn't do that you did and we'll try to help.

But we aren't giving you code you can hand in as your own work ...
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900