반응형

자판기를 만들어보자!!

구조로는 


app.c


#include "main.h"
#include "japan.h"

void MemuDisplay()
{
	puts("1. 음료 삽입");
	puts("2. 음료 삭제");
	puts("3. 현황 검색");
	puts("4. 저장");
	puts("5. 로딩");
	puts("0. 종료");
}
int inputNo()
{
	int No;
	printf("INPUT :");
	scanf("%d",&No);
	return No;
}
void selectMenu(int key,JAPANGI* (*japan)[10])
{
	switch(key)
	{
	case 1:
		japan_add(japan); break;
	case 2:
		//function2(); break;
	case 3:
		japan_display(japan); break;
	case 0:
		exit(0);
	default:
		//puts("잘못된 값");
		break;
	}
}

void Run(JAPANGI* (*japan)[10])
{
	japan_array(japan);
	printf("테스트완료\n--------------\n");
	int key =0;

	japan[0][9]->beverage = "콜라";
	japan[1][9]->beverage="커피";
	japan[2][9]->beverage="사이다";
	japan[3][9]->beverage="박카스";
	japan[4][9]->beverage="생수";
	japan[1][8]->beverage="커피";

	japan_display(japan);



	while(1)
	{
		
		MemuDisplay();
		
		key = inputNo();

		system("cls");
		selectMenu(key,japan);
		puts("계속하시려면 아무키나 누르세요!!");
		getch();
	}
}


japan.c


#include "main.h"
#include "app.h"
//초기화

void japan_array(JAPANGI* (*japan)[10])
{
	for(int i=0;i<5;i++)
	{

		for(int j=0;j<10;j++)
		{
			japan[i][j] = (JAPANGI*)malloc(sizeof(JAPANGI));
			japan[i][j]->beverage = (char*)malloc(sizeof(char)*10);
			//strcpy(japan[i][j]->beverage,"");
			japan[i][j]->beverage = "";
			japan[i][j]->Price = 0;
		}
	}
}

//화면 출력!
void japan_display(JAPANGI* (*japan)[10])
{

	for(int i=0;i<10;i++)
	{
		for(int j=0;j<5;j++)
		{
			if(japan[j][i]->beverage != "")
				printf("| %s |",japan[j][i]->beverage);
			else
				printf("|      |");
		}
		printf("\n");
	}
}

void japan_add_1(JAPANGI* (*japan)[10],int index,int b)
{

	char* temp;
	char* temp_1;
	temp = (char*)calloc(10,sizeof(char));
	temp_1 = (char*)calloc(10,sizeof(char));
	if(index == 0)
	{
		temp = "콜라";
	}
	else if(index == 1)
	{
		temp ="커피";
	}
	else if(index == 2)
	{
		temp ="사이다";
	}
	else if(index == 3)
	{
		temp ="박카스";
	}
	else if(index == 4)
	{
		temp ="생수";
	}
	printf("테스트%s\n",temp);


	for(int c=0;cbeverage != temp)
			{
				printf("테스트\n");
				japan[index][i]->beverage = temp;
				break;
			}
		}
	}
}
//음료수 추가
void japan_add(JAPANGI* (*japan)[10])
{
	int a,b,index;
	printf("음료를 추가해주세요\n");
	printf(" 1:콜라  2:커피  3:사이다  4:박카스  5:생수\n 입력: ");
	scanf("%d",&a);
	printf("갯수를 입력해주세요\n 입력: ");
	scanf("%d",&b);
	switch(a)
	{
	case 1:
		index = 0;
		japan_add_1(japan,index,b);
		break;
	case 2:
		index = 1;
		japan_add_1(japan,index,b);
		break;
	case 3:
		index = 2;
		japan_add_1(japan,index,b);
		break;
	case 4:
		index = 3;
		japan_add_1(japan,index,b);
		break;
	case 5:
		index = 4;
		japan_add_1(japan,index,b);
		break;
	default:
		printf("잘못된 값 입력");
		break;
	}

}


main.c


#include "main.h"
#include "app.h"


void main()
{
	JAPANGI* japan[5][10];
	Run(japan);
}




app.h


void Run(JAPANGI* (*japan)[10]);
void selectMenu(int key);
int inputNo();
void MemuDisplay();


japan.h


void japan_array(JAPANGI* (*japan)[10]);
void japan_display(JAPANGI* (*japan)[10]);
void japan_add(JAPANGI* (*japan)[10]);
void japan_add_1(JAPANGI* (*japan)[10],int index,int b);


main.h


#include 
#include 
#include 
#include 
#include 

typedef struct japangi
{
	char* beverage;
	int Price;
}JAPANGI;


+ Recent posts