-
반응형
#define SIZE 10
#include <stdio.h>
char askReservation();
void printSeats(int s[], int size);
void processReservation(int s[], int size, int seatNumber);
int main(void)
{
int seatChoice;
int seats[SIZE] = { 0 };
printf("******좌석 예약 시스템******\n");
while (askReservation() == 'y')
{
printSeats(seats, SIZE);
printf("몇번째 좌석? ");
scanf("%d", &seatChoice);
processReservation(seats, SIZE, seatChoice);
while (getchar() != '\n'); // 버퍼 비움
}
}
char askReservation()
{
char choice;
printf("\n좌석을 예약하시겠습니까?(y/n)");
scanf("%c", &choice);
return choice;
}
void processReservation(int s[], int size, int seatNumber)
{
if (s[seatNumber - 1] == 0)
{
s[seatNumber - 1] = 1;
printf("예약되었습니다.\n");
printSeats(s, SIZE);
}
else
{
printf("이미 예약된 자리입니다.\n");
}
}
void printSeats(int s[], int size)
{
int i;
printf("\n----------------------------------\n");
printf(" 1 2 3 4 5 6 7 8 9 10\n");
printf("----------------------------------\n");
for (i = 0; i < SIZE; i++)
printf("%3d", s[i]);
printf("\n");
}
결과:
반응형'코딩 > C언어' 카테고리의 다른 글
합집합 && 교집합 && 차집합 (0) 2018.09.27 값 탐색 && 가장 큰 수 && 총 합 (0) 2018.09.27 집합이 같은지 비교 (0) 2018.09.27 난수 발생 후 정리 (0) 2018.09.27 거스름돈 계산 (0) 2018.09.04