Please tell me the sentence in C language while

Asked 2 weeks ago, Updated 2 weeks ago, 1 views

Once the while statement is rotated in this code, the next when statement is executed, the next code is executed instead of the top sentence. How do I get the things below to run after it's run?

#include <stdio.h>
#define SIZE 10

int main() {
    char c = 0;
    int weight = 0, height = 0;
    int theater[SIZE][SIZE] = { 0 };

    while (1) {

        printf ("Would you like to reserve a seat at the theater? (y/n)));
        scanf_s("%c", &c);

        if (c == 'n')
            break;

            printf ("Purchase available seats\n\n");
            printf("    1  2  3  4  5  6  7  8  9  10\n");
            printf("    -----------------------------\n");
            for (int i = 0; i < SIZE; i++) {
                printf("%d|", i + 1);
                for (int j = 0; j < SIZE; j++)
                    printf(" %d ", theater[i][j]);
                printf("\n");
            }

            printf("\nPlease enter your reserved seat number:");
            scanf_s("%d %d", &weight, &height);

            if (weight <= 0 || weight > SIZE) {
                printf ("Please enter a number between 1 and 10";
                continue;
            }
            if (theater[weight - 1][height - 1] == 0) {
                theater[weight - 1][height - 1] = 1;
                printf ("reserved".\n");
            }

            else
                printf("Already Reserved". Please choose a different seat.\n");
        }

    return 0;
}

c

2022-09-20 15:57

1 Answers

There is a problem with the code below.

scanf_s("%c", &c);

Change the code above as below.

scanf_s(" %c", &c, (unsigned int)sizeof(char));

To receive user input of Korean characters in the scanf series function, you must leave a space in front of %c. For a detailed explanation of this, please refer to the article below as there are answers to the same question in the past.

https://hashcode.co.kr/questions/12755


2022-09-20 15:57

If you have any answers or tips


© 2022 pinfo. All rights reserved.