본문 바로가기
C언어/따배씨 c언어

[따배씨] 8.8 메뉴만들기 예제

by newbeverse 2022. 12. 7.

 

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

void avengers(void)
{
	printf("Avengers assemble!\n");

	return 0;
}

void beep(void)
{
	printf("\a\n");
	
	return 0;
}

void count(void)
{
	long input;
	long num = 1;
	char c;

	while (scanf("%ld", &input) != 1)
	{
		printf("Your input - ");

		while ((c = getchar()) != '\n')
			putchar(c);
		
		printf(" - is not a integer. Please try again. \n");

	}

	while (input + 1 > num)
	{

		printf("%ld\n", num);


		num = num + 1;
	}

	return 0;
}


int main()
{
	char c;

	printf("Enter the letter of your choice: \n");
	printf("a. avengers    b. beep\n");
	printf("c. count       q. quit\n");
	
	while (scanf("%c", &c) != 0)
	{
		if (c == 'a')
			avengers();
		else if (c == 'b')
			beep();
		else if (c == 'c')
			count();
		else if (c == 'q')
			return 0;
		else
			printf("You need to choice in a to q");
		while ((c = getchar()) != '\n')
			continue;
		
		printf("Enter the letter of your choice: \n");
		printf("a. avengers    b. beep\n");
		printf("c. count       q. quit\n");
	}

	return 0;
}
반응형