How to check if the seat is free and if not ask the user to type again by inserting an 'X' in the space occupied?

0

I need the user to insert where he wants to sit, informing the row and column that he wants, if the user chooses the position 0-1 the program will register and write to a txt file later this information, and it will enter a looping to register a new user, where it will enter what position it wants and if it enters a position where it is already occupied by another user < strong> will not accept by placing an X in place to demonstrate that you are busy.

Follow the code ...

#include<stdio.h>
#include <stdlib.h>

void main()
{
    printf("\n \nEscolha seu assento: \n\n");

    int m, n, fileira, assento;
    int lugares[10][16];

    for(m=1;m<10;m++){
        for(n=1;n<16;n++){
            printf("[%d- %d]", m, n);
        }

        printf("\n");   
    }

    printf("\nFileira desejada: ");
    scanf("%d",&fileira);
    printf("Assento desejado: ");
    scanf("%d",&assento);

    system("pause");
}
    
asked by anonymous 28.11.2018 / 06:06

1 answer

0

I think it's almost over then. Just add this already done code in a while and create a boolean control variable to end the loop. I do not know if I understand how you will manage the places, but I will assume it is 0 for vacant and 1 for busy. In your for then add:

lugares[m][n] = 0;

Then loop:

bool encerrar = false;

while (!encerrar)
{
    //seu código sem as declarações das váriaveis.

    if (lugares[fileira][assento] == 1)
        printf("Posicao Ocupada!\n");
    else
        lugares[fileira][assento] = 1;
}

I think there's a good start there to continue ..

    
28.11.2018 / 11:08