Thread: Cinema Seat Selection HELP!

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    1

    Cinema Seat Selection HELP!

    I can't seem to find the bugs causing the errors. No matter what the default clause in my switch will keep printing and running whatever that is in it. Plus my if statement in the end keeps coming out no matter what in my first ticket choice. And I get alot of warnings. Sorry i am pretty new to C and this is my first project so.. Here's my code i hope you guys could help out

    Code:
    int SeatsSelectionStandard()
    {
        int counter = 1;
        int row = 0;
        int column = 0;
        char rowid;
        int i,j;
        
        int A[8][8] = {
            { 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8" },
            { 0, "B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8" },
            { 0, "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8" },
            { 0, "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8" },
            { 0, "E1", "E2", "E3", "E4", "E5", "E6", "E7", "E8" },
            { 0, "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8" },
            { 0, "G1", "G2", "G3", "G4", "G5", "G6", "G7", "G8" },
        };
        
        int taken [8][8] = {
            { 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0 },    
        };
        
        printf ("=====================The Screen=====================\n\n\n"); 
        for (i = 1; i<=7; i++)
        {
            for (j = 1; j <= 7;j++)
            printf("%s\t" , A[i][j]);
            printf("\n");
        }
            printf("\n\nChoose Your Seat :\n");    
            printf("Press Z1 when done\n");    
        do
        {                            // ask for seat row and collumn
            scanf("%c %d" , &rowid,&column);
            
            switch (rowid) 
                {
                
                case 'a':
                case 'A':
                { 
                row = 1;
                
                if (taken[row][column] == 1)
                {
                printf("\n\nThis seat is taken , try again\n");
            seatspurchased--;
            }
                
                    taken [row][column] = 1;
                    printf("=====================The Screen=====================\n\n\n");
                    for (i = 1; i <= 7;i++)
                    {
                        for (j = 1;j<=7; j++)
                        {
                            if (taken[i][j] ==0)
                             printf("%s\t" , A[i][j]);
                            else if (taken[i][j] == 1)
                            printf("[%s]\t", A[i][j]);                        
                            
                        }printf("\n");
                    }
                    printf("Press Z1 when done\n");
                    printf("\n\nChoose Your Seat :\n");
                    seatspurchased++;    
                    break;
                }
                
                case 'b':
                case 'B':
                { 
                row = 2;
                
                if (taken[row][column] == 1)
                {
                printf("\n\nThis seat is taken , try again\n");
                seatspurchased--;
            }
                
                    taken [row][column] = 1;
                    printf ("=====================The Screen=====================\n\n\n"); 
                    for (i = 1; i <= 7;i++)
                    {
                        for (j = 1;j<=7; j++)
                        {
                            if (taken[i][j] ==0)
                            printf("%s\t" , A[i][j]);
                            else if (taken[i][j] == 1)
                            printf("[%s]\t", A[i][j]);                    
                        }printf("\n");
                    }
                    printf("Press Z1 when done\n");
                    printf("\n\nChoose Your Seat :\n");        
                    seatspurchased++;
                    break;
                }
                
                case 'c':
                case 'C':
                { 
                row = 3;
                
                if (taken[row][column] == 1)
                {
                printf("\n\nThis seat is taken , try again\n");
                seatspurchased--;
            }
                    taken [row][column] = 1;
                    printf ("=====================The Screen=====================\n\n\n"); 
                    for (i = 1; i <= 7;i++)
                    {
                        for (j = 1;j<=7; j++)
                        {
                            if (taken[i][j] ==0)
                            printf("%s\t" , A[i][j]);
                            else if (taken[i][j] == 1)
                            printf("[%s]\t", A[i][j]);                        
                        }printf("\n");
                    }
                    printf("Press Z1 when done\n");
                    printf("\n\nChoose Your Seat :\n");    
                    seatspurchased++;
                    break;
                }
                
                case 'd':
                case 'D':
                { 
                row = 4;
                
                if (taken[row][column] == 1)
                {
                printf("\n\nThis seat is taken , try again\n");
                seatspurchased--;
            }
                    taken [row][column] = 1;
                    printf ("=====================The Screen=====================\n\n\n"); 
                    for (i = 1; i <= 7;i++)
                    {
                        for (j = 1;j<=7; j++)
                        {
                            if (taken[i][j] ==0)
                            printf("%s\t" , A[i][j]);
                            else if (taken[i][j] == 1)
                            printf("[%s]\t", A[i][j]);                        
                        }printf("\n");
                    }
                    printf("Press Z1 when done\n");
                    printf("\n\nChoose Your Seat :\n");    
                    seatspurchased++;
                    break;
                }
                
                case 'e':
                case 'E':
                { 
                row = 5;
                
                if (taken[row][column] == 1)
                {
                printf("\n\nThis seat is taken , try again\n");
                seatspurchased--;
            }
                    taken [row][column] = 1;
                    printf ("=====================The Screen=====================\n\n\n"); 
                    for (i = 1; i <= 7;i++)
                    {
                        for (j = 1;j<=7; j++)
                        {
                            if (taken[i][j] ==0)
                            printf("%s\t" , A[i][j]);
                            else if (taken[i][j] == 1)
                            printf("[%s]\t", A[i][j]);                        
                        }printf("\n");
                    }
                    printf("Press Z1 when done\n");
                    printf("\n\nChoose Your Seat :\n");    
                    seatspurchased++;
                    break;
                }
                
                case 'f':
                case 'F':
                { 
                row = 6;
                
                if (taken[row][column] == 1)
                {
                printf("\n\nThis seat is taken , try again\n");
                seatspurchased--;
            }
                    taken [row][column] = 1;
                    printf ("=====================The Screen=====================\n\n\n"); 
                    for (i = 1; i <= 7;i++)
                    {
                        for (j = 1;j<=7; j++)
                        {
                            if (taken[i][j] ==0)
                            printf("%s\t" , A[i][j]);
                            else if (taken[i][j] == 1)
                            printf("[%s]\t", A[i][j]);                        
                        }printf("\n");
                    }
                    printf("Press Z1 when done\n");
                    printf("\n\nChoose Your Seat :\n");    
                    seatspurchased++;
                    break;
                }
                
                case 'g':
                case 'G':
                { 
                row = 7;
                
                if (taken[row][column] == 1)
                {
                printf("\n\nThis seat is taken , try again\n");
                seatspurchased--;
            }
                    taken [row][column] = 1;
                    printf ("=====================The Screen=====================\n\n\n");
                    for (i = 1; i <= 7;i++)
                    {
                        for (j = 1;j<=7; j++)
                        {
                            if (taken[i][j] ==0)
                            printf("%s\t" , A[i][j]);
                            else if (taken[i][j] == 1)
                            printf("[%s]\t", A[i][j]);                        
                        }printf("\n");
                    }
                    printf("Press Z1 when done\n");
                    printf("\n\nChoose Your Seat :\n");
                    seatspurchased++;
                    break;
                }
                
                case 'z':
                case 'Z':
                { 
                    row = 100;
                    counter = 0;
                    purchased();
                }
                
                default:
                {
                    printf("Invalid Input. Please try again\n");
                    row=11;
                }
        }
            
        }
        
            
            if (((row<1|| row >10) || (column<1 || column>10))&&(row!=100)) 
            printf("Wrong choice , try again\n");
    
    
        } while(counter == 1);
    }
    
    int main()
    {
     SeatsSelectionStandard();
    
    return 0;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You need to:
    • Indent your code properly.
    • Break down your code into smaller functions that do one thing and do it well.
    • Test your code piece by piece, e.g., implement one of the smaller functions, test, fix, test again, etc. Implement another one of the smaller functions, test, fix, test again, etc.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Your switch statement is insane. It's primarily being used to calculate row. Get rid of it and all that repeated code.
    Code:
    row = toupper(rowid) - 'A' + 1;   // toupper() is prototyped in <ctype.h>

  4. #4
    Registered User naaissus's Avatar
    Join Date
    Jan 2016
    Location
    Balkan
    Posts
    23
    Hi

    You shouldn't ignore warnings. I can't even compile your program.

    |18|error: too many initializers for 'int [8]'| (several times)
    You have reserved only 8x8 locations for matrix A but you are trying to put 7x9 + 1x8 elements in it.

    |18|error: invalid conversion from 'const char*' to 'int' [-fpermissive]| (several times)
    Matrix A is declared as matrix of ints, but you're trying to initialise it with string values ("A1" - "G8").
    So it needs to be matrix of strings (arrays of characters).

    |268|warning: no return statement in function returning non-void [-Wreturn-type]|
    You need to put return statements at the end of your functions to remove this warning.

    Also, I got this:
    |264|error: expected 'while' before '(' token|
    |265|error: expected ';' before 'printf'|
    |268|error: expected unqualified-id before 'while'|
    |269|error: expected declaration before '}' token|
    You really need to indent your code properly because it's impossible to find out what goes where and I think that I've spotted several logical errors but I can't be sure.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with cinema group seats reservation
    By LiquidSpirit in forum C Programming
    Replies: 3
    Last Post: 12-27-2014, 05:01 AM
  2. Replies: 0
    Last Post: 07-15-2014, 02:43 PM
  3. Replies: 4
    Last Post: 03-17-2012, 09:08 AM
  4. Pls Help: Assigning of Passenger Seat
    By Jana in forum C Programming
    Replies: 3
    Last Post: 11-12-2011, 03:56 PM
  5. creating a cinema seat
    By SweeLeen in forum C++ Programming
    Replies: 2
    Last Post: 01-05-2006, 03:34 AM

Tags for this Thread