MIPI_BaseC_WebinarFRTK/06_Lecture06/16_coffee_p43.c

69 lines
1.6 KiB
C
Raw Permalink Normal View History

2024-11-13 09:22:28 +03:00
#include <stdio.h>
#include <conio.h>
int Rubl_1 = 0,Rubl_2 = 0,Cancel = 0;
enum signals { RUBL_1, RUBL_2, CANCEL, NONE};
void GetUserSignal(void)
{
char Choice;
while(1)
{
printf("1.Put 1 rubl\n2.Put 2 rubl\n0.Cancel\n");
Choice = _getch();
switch(Choice)
{
case '1': Rubl_1=1; return;
case '2': Rubl_2=1; return;
case '0': Cancel=1; return;
}
}
}
int main()
{
enum states { READY, PREPFRE, WAIT, CHANGE, RETURN } state = READY;
// enum signals signal;
while (1)
{
switch (state)
{
case READY:
printf("Ready\n");
GetUserSignal();
if(Rubl_2)
state = PREPFRE;
if(Rubl_1)
state = WAIT;
break;
case PREPFRE:
printf("Preapare cofee\n");
state = READY;
break;
case WAIT:
printf("Wait\n");
GetUserSignal();
if(Rubl_2)
state = CHANGE;
if(Rubl_1)
state = PREPFRE;
if(Cancel)
state = RETURN;
break;
case CHANGE:
printf("Change 1 Rubl\n");
state = PREPFRE;
break;
case RETURN:
printf("Change 1 Rubl\n");
state = READY;
break;
}
Rubl_1 = 0;
Rubl_2 = 0;
Cancel = 0;
}
return 0;
}