Thread: Booking in a theatre program

  1. #1
    Registered User
    Join Date
    Jan 2012
    Location
    KaisarianĂ.., Attiki, Greece, Greece
    Posts
    4

    Booking in a theatre program

    Guys I could use some help!
    I have a C program project about booking in a theatre.
    So we have this theatre that has 10 rows and 4 seats in every row.
    So the seats of the first row are A1,A2,A3 and A4.
    This program must show all the empty seats and the program must give the alternatives:
    Press E to show all the seats
    Press K to book a seat
    Press Q to exit the program
    For the alternatives I must use a function( void menu() ).
    If the user press E the program must show all the seats(empty or not).
    If the user press K then the program asks the user the number of seats he wants to book and the user must print the number of the seat he wants(for example A1).
    Use a two-dimensional array to show the theatre seats.
    For example the [0][0] is the A1 or the [0][1] is the A2 e.t.c.
    At first every seat is empty so every seat in our array has 0.When we see 0 we will understandtha a seat is empty.
    When a seat is booked the array object will have 1 so the user knows that this seat is taken.
    The program must not book a seat that is taken.
    When a user press K but all the seats are taken the program must show the neccesary message.
    This procedure must go on until all the seats are taken or we press Q.

    Thank you a lot,
    Ace Rockson

  2. #2

  3. #3
    Registered User
    Join Date
    Jan 2012
    Location
    KaisarianĂ.., Attiki, Greece, Greece
    Posts
    4
    Code:
    #include <stdio.h>
     #include <stdlib.h>
     #include <math.h>
     int sira;
     int stili;
     int A[9][3];
     char answer;
     int oles_piasmenes;
     int e_sinartisi(int A[9][3], int sira, int stili);
     int k_sinartisi(int A[9][3], int oles_piasmenes);
     
     int main(void)
     {
     answer='a';
     sira=0;
     stili=0;
     oles_piasmenes=0;
     while(sira<=9)
     {
     while(stili<=3)
     {
     A[sira][stili]=0;
     stili++;
     }
     stili=0;
     sira++;
     }
     
     while(answer!='Q' && oles_piasmenes!=1)
     {
     system("pause");
     system("cls");
     printf("Parakalo pliktrologiste E gia <<Emfanisi thesewn>>.\n");
     printf("Parakalo pliktrologiste K gia <<Kratisi thesewn>>.\n");
     printf("Parakalo pliktrologiste Q gia eksodo apo to programma.\n");
     scanf_s("%c\n", answer);
     if(answer!='E' && answer!='K' && answer!='Q')
     {
     printf("Prosoxi pliktrologisate lathos apantisi.\n");
     printf("\nH apantisi prepei na einai me kefalaia kai agglika!\n");
     system("sleep 4");
     }
     if(answer=='E')
     { 
     sira=0;
     stili=0;
     int e_sinartisi(A[9][3]);
     int sira;
     int stili;
     sira=0;
     stili=0;
     }
     if(answer=='K')
     {
     int k_sinartisi(int A[9][3],int oles_piasmenes);
     
     }
     }
     if(oles_piasmenes==1)
     {
     system("pause");
     printf("Oles oi theseis einai piasmenes!\n");
     system("cls");
     }
     return 0;
     }
     int e_sinartisi(int A[9][3], int sira, int stili)
     {
     stili=0;
     sira=0;
     while(sira<=9)
     {
     while(stili<=3)
     {
     if(A[sira][stili]==0)
     {
     if(sira==0)
     {
     sira=sira+1;
     printf("H thesi A%d einai kaini.\n", sira);
     sira=sira-1;
     }
     if(sira==1)
     {
     sira=sira+1;
     printf("H thesi B%d einai kaini.\n", sira);
     sira=sira-1;
     }
     if(sira==2)
     {
     sira=sira+1;
     printf("H thesi C%d einai kaini.\n", sira);
     sira=sira-1;
     }
     if(sira==3)
     {
     sira=sira+1;
     printf("H thesi D%d einai kaini.\n", sira);
     sira=sira-1;
     }
     if(sira==4)
     {
     sira=sira+1;
     printf("H thesi E%d einai kaini.\n", sira);
     sira=sira-1;
     }
     if(sira==5)
     {
     sira=sira+1;
     printf("H thesi F%d einai kaini.\n", sira);
     sira=sira-1;
     }
     if(sira==6)
     {
     sira=sira+1;
     printf("H thesi G%d einai kaini.\n", sira);
     sira=sira-1;
     }
     if(sira==7)
     {
     sira=sira+1;
     printf("H thesi H%d einai kaini.\n", sira);
     sira=sira-1;
     }
     if(sira==8)
     {
     sira=sira+1;
     printf("H thesi I%d einai kaini.\n", sira);
     sira=sira-1;
     }
     if(sira==9)
     {
     sira=sira+1;
     printf("H thesi J%d einai kaini.\n", sira);
     sira=sira-1;
     }
     }
     stili++;
     }
     stili=0;
     sira++;
     }
     } 
     
     
     
     
     int k_sinartisi(int A[9][3], int oles_piasmenes)
     {
     int x;
     int m;
     int xsir;
     int xst;
     x=0;
     printf("Parakalo pliktrologiste ton arithmo theseon gia kratisi.\n");
     scanf_s("%d\n", x);
     m=1;
     while(m<=x)
     {
     system("cls");
     printf("Parakalo pliktrologiste ton arithmo siras kai stilis gia tin tsesi.\n");
     printf("Prota ton arithmo siras, keno kai meta ton arithmo stilis, meta stin\n");
     printf("epomeni epanalipsi to idio gia tin epomeni thesi.\n");
     int scanf_s(const char*_Format, xsir, xst);
     if(A[xsir][xst]==0)
     {
     A[xsir][xst]=1;
     }
     else
     {
     printf("Kanate lathos, i thesi pou epileksate einai piasmeni!\n");
     system("pause");
     system("cls");
     printf("Tha ksanapliktrologisete tin thesi ayti!\n");
     system("pause");
     m--;
     }
     m++;
     return 0;
     }
     }
    this is the source code.
    is anything wrong??
    ignore the messages in print f...it's greek

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    Don't you have a compiler in order to test it?
    Devoted my life to programming...

  5. #5
    Registered User
    Join Date
    Jan 2012
    Location
    KaisarianĂ.., Attiki, Greece, Greece
    Posts
    4
    i can't and i don't know why...can you please give me a clue?

  6. #6
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    What are your error messages? Sorry, the code is long and I don't have my compiler right now.
    Devoted my life to programming...

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    First, learn the value of indentation -> SourceForge.net: Indentation - cpwiki
    You can spot many kinds of bugs very easily just by indenting properly and consistently. For example, you would ask why there is a return statement at line 154 INSIDE the while loop!.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int sira;
    int stili;
    int A[9][3];
    char answer;
    int oles_piasmenes;
    int e_sinartisi(int A[9][3], int sira, int stili);
    int k_sinartisi(int A[9][3], int oles_piasmenes);
    
    int main(void)
    {
      answer = 'a';
      sira = 0;
      stili = 0;
      oles_piasmenes = 0;
      while (sira <= 9) {
        while (stili <= 3) {
          A[sira][stili] = 0;
          stili++;
        }
        stili = 0;
        sira++;
      }
    
      while (answer != 'Q' && oles_piasmenes != 1) {
        system("pause");
        system("cls");
        printf("Parakalo pliktrologiste E gia <<Emfanisi thesewn>>.\n");
        printf("Parakalo pliktrologiste K gia <<Kratisi thesewn>>.\n");
        printf("Parakalo pliktrologiste Q gia eksodo apo to programma.\n");
        scanf("%c\n", answer);  //!! not scanf_s
        if (answer != 'E' && answer != 'K' && answer != 'Q') {
          printf("Prosoxi pliktrologisate lathos apantisi.\n");
          printf("\nH apantisi prepei na einai me kefalaia kai agglika!\n");
          system("sleep 4");
        }
        if (answer == 'E') {
          sira = 0;
          stili = 0;
    //       int e_sinartisi(A[9][3]);
    //       int sira;
    //       int stili;
          sira = 0;
          stili = 0;
        }
        if (answer == 'K') {
          int k_sinartisi(int A[9][3], int oles_piasmenes);
    
        }
      }
      if (oles_piasmenes == 1) {
        system("pause");
        printf("Oles oi theseis einai piasmenes!\n");
        system("cls");
      }
      return 0;
    }
    
    int e_sinartisi(int A[9][3], int sira, int stili)
    {
      stili = 0;
      sira = 0;
      while (sira <= 9) {
        while (stili <= 3) {
          if (A[sira][stili] == 0) {
            if (sira == 0) {
              sira = sira + 1;
              printf("H thesi A%d einai kaini.\n", sira);
              sira = sira - 1;
            }
            if (sira == 1) {
              sira = sira + 1;
              printf("H thesi B%d einai kaini.\n", sira);
              sira = sira - 1;
            }
            if (sira == 2) {
              sira = sira + 1;
              printf("H thesi C%d einai kaini.\n", sira);
              sira = sira - 1;
            }
            if (sira == 3) {
              sira = sira + 1;
              printf("H thesi D%d einai kaini.\n", sira);
              sira = sira - 1;
            }
            if (sira == 4) {
              sira = sira + 1;
              printf("H thesi E%d einai kaini.\n", sira);
              sira = sira - 1;
            }
            if (sira == 5) {
              sira = sira + 1;
              printf("H thesi F%d einai kaini.\n", sira);
              sira = sira - 1;
            }
            if (sira == 6) {
              sira = sira + 1;
              printf("H thesi G%d einai kaini.\n", sira);
              sira = sira - 1;
            }
            if (sira == 7) {
              sira = sira + 1;
              printf("H thesi H%d einai kaini.\n", sira);
              sira = sira - 1;
            }
            if (sira == 8) {
              sira = sira + 1;
              printf("H thesi I%d einai kaini.\n", sira);
              sira = sira - 1;
            }
            if (sira == 9) {
              sira = sira + 1;
              printf("H thesi J%d einai kaini.\n", sira);
              sira = sira - 1;
            }
          }
          stili++;
        }
        stili = 0;
        sira++;
      }
    }
    
    int k_sinartisi(int A[9][3], int oles_piasmenes)
    {
      int x;
      int m;
      int xsir;
      int xst;
      x = 0;
      printf("Parakalo pliktrologiste ton arithmo theseon gia kratisi.\n");
      scanf("%d\n", x); //!! not scanf_s
      m = 1;
      while (m <= x) {
        system("cls");
        printf("Parakalo pliktrologiste ton arithmo siras kai stilis gia tin tsesi.\n");
        printf("Prota ton arithmo siras, keno kai meta ton arithmo stilis, meta stin\n");
        printf("epomeni epanalipsi to idio gia tin epomeni thesi.\n");
        //!! int scanf_s(const char *_Format, xsir, xst);
        if (A[xsir][xst] == 0) {
          A[xsir][xst] = 1;
        } else {
          printf("Kanate lathos, i thesi pou epileksate einai piasmeni!\n");
          system("pause");
          system("cls");
          printf("Tha ksanapliktrologisete tin thesi ayti!\n");
          system("pause");
          m--;
        }
        m++;
        return 0;
      }
    }
    Second, avoid microsoft's attempts to create a non-standard "safe" API by appending _s on the end of everything.
    1. It's only safe if you know what you're doing.
    2. If you know what you're doing, you may as well use the ANSI/ISO standard functions anyway.
    All you succeed in doing is making it harder for other people to help you (if they're not ms users).

    Finally, some issues to fix.
    Code:
    $ gcc -Wall foo.c
    foo.c: In function ‘main’:
    foo.c:34: warning: format ‘%c’ expects type ‘char *’, but argument 2 has type ‘int’
    foo.c: In function ‘k_sinartisi’:
    foo.c:135: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’
    foo.c:156: warning: control reaches end of non-void function
    foo.c: In function ‘e_sinartisi’:
    foo.c:125: warning: control reaches end of non-void function
    foo.c: In function ‘k_sinartisi’:
    foo.c:143: warning: ‘xsir’ may be used uninitialized in this function
    foo.c:143: warning: ‘xst’ may be used uninitialized in this function
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Jan 2012
    Location
    KaisarianĂ.., Attiki, Greece, Greece
    Posts
    4
    no message at all -_-

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hotel Booking system
    By TenTierHook in forum C++ Programming
    Replies: 3
    Last Post: 03-16-2010, 06:53 AM
  2. Movie Theatre projection technology
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 04-09-2007, 02:56 AM
  3. Airline Booking System - PLZ HELP
    By Gecko2099 in forum C Programming
    Replies: 5
    Last Post: 03-26-2005, 12:17 PM
  4. Booking seats program question..
    By snapshooter in forum C++ Programming
    Replies: 7
    Last Post: 12-24-2004, 06:09 PM

Tags for this Thread