#include <stdio.h>
void print_menu()
{
printf("Please choose one of the following : \n");
printf("1) Sum \n");
printf("2) Difference \n");
printf("3) Multiplication \n");
printf("4) Quit \n");
printf("Enter the number of your choice : ");
}
void sum(int a, int b)
{
printf("Input two numbers :");
scanf("%d %d",&a,&b);
printf("%d\n",a+b);
}
void difference(int a, int b)
{
printf("Input two numbers :");
scanf("%d %d",&a,&b);
if(a>b)
printf("max=%d\t min=%d\n",a,b);
else
printf("max=%d\t min=%d\n",b,a);
}
void multiplication(int a, int b)
{
printf("Input two numbers :");
scanf("%d %d",&a,&b);
printf("%d\n",a*b);
}
void exit()
{
exit;
}
void quit()
{
exit();
}
void m_menu(int x)
{
int a,b;
switch(x) {
case 1 : sum(a,b); break;
case 2 : difference(a,b); break;
case 3 : multiplication(a,b); break;
case 4 : quit(); break;
default : printf("Enter the number of 1 to 4 : ");
}
}
void main()
{
int n;
print_menu();
scanf("%d",&n);
m_menu(n);
}
이런 프로그램입니다.
예를들어 1)sum 을 선택해서 두수를 넣으면 답이 나옵니다.
답이 나오면서 프로그램이 종료되어 버립니다.
답이 나오면서 종료되지 않고 다시 메뉴가 출력되어서 4)quit 를 선택할때까지
계속 반복하는 방법이 궁금합니다.
그리고 exit 에 대해서도 궁금합니다. exit가 함수인지 아니면 명령어인지..
프로토타입을 설정하고 그러다 보니까
void quit() 와 void exit()로 나누었습니다.
4)quit 선택할때까지 반복하는것과 exit 에 대해서 궁금합니다~~~
.
|