#include <stdio.h>
#include <stdlib.h>

void
clrscr ()
{
  // system("clear"); // -- linux
  system ("cls");		// -- windows
}

// printing the menu
void
printMenu (const char *title, const char **men, int len)
{
  if (title[0] != '\0')
    {
      printf ("\n---- %s ----\n", title);
    }
  // old style
  int i;
  for (i = 0; i < len; i++)
    {
      printf (" (%d) %s\n", i + 1, men[i]);
    }
  printf ("\n");
}

// number choice
int
askChoice ()
{
  int ch;
  printf ("\nChoice : ");
  scanf ("%d", &ch);
  return ch;
}

// Yes or no choice
char
YesNo ()
{
  char ch;
  printf ("\nYes / No [Y/N]: ");
  scanf (" %c", &ch);

  // convert into Yes or No..
  // y or Y => Yes, anything else => No
  if (ch != 'y' || ch != 'Y')
    {
      ch = 'N';
    }
  else if (ch == 'y')
    {
      ch = 'Y';
    }

  return ch;
}

void
divider ()
{
  printf ("\n--------------------------------\n");
}

void
title (const char *str)
{
  divider ();
  printf ("     %s", str);
  divider ();
}

void
printPrice (double totalP, int totalI)
{
  divider ();
  printf ("Total items : %d\n", totalI);
  printf ("Total price : php%g", totalP);
  divider ();
}

void
invalid ()
{
  divider ();
  printf (" Invalid choice !");
}

int
main ()
{

  // main variables
  double totalPrice = 0.0;
  int totalItems = 0;

  // change the number of mainMenuItems as you add new items to mainMenu
  int mainMenuItems = 6;
  const char *mainMenu[] = {
    "Buy 1 take 1", "Single Order", "Beverages", "Check out", "Reset", "Exit"
  };

  // don't quit right away
  int quit = 0;

  // mainMenu section
  int choice, i;
  clrscr ();			// clear screen
mainMenu:

  title ("Thai me UP");

  for (i = 0; i < mainMenuItems; i++)
    {
      printf (" (%d): %s\n", i + 1, mainMenu[i]);
    }

  printPrice (totalPrice, totalItems);

  // ask for a choice
  choice = askChoice ();

  if (choice < 1 || choice > mainMenuItems)
    {
      // invalid choice
      clrscr ();
      invalid ();
      goto mainMenu;

    }
  else if (choice == 1)
    {
      clrscr ();

      // Buy 1 take 1
    buy1take1:

    int menuItems = 3;	// change as you add / remove items

      // Menu
    const char *menu[] = {
	"Burger", "Cheese Burger", "Hotdog sandwich"	// , ... add more
      };

      // prices of menu
    const double prices[] = {
	40, 50, 50		// , ... add more
      };

    title ("Buy 1 Take 1");

      // all options
      for (i = 0; i < menuItems; i++)
	{
	  printf (" (%d) %s : php%g\n", i + 1, menu[i], prices[i]);
	}

      // back
      printf (" (%d) Back\n", menuItems + 1);

      printPrice (totalPrice, totalItems);

      choice = askChoice ();
      if (choice < 1 || choice > menuItems + 1)
	{
	  // invalid choice
	  clrscr ();
	  invalid ();
	  goto buy1take1;
	}
      if (choice == menuItems + 1)
	{
	  // back
	  clrscr ();
	  goto mainMenu;
	}

      totalPrice += prices[choice - 1];
      totalItems += 1;

      clrscr ();
      goto buy1take1;
    }
  else if (choice == 2)
    {
      clrscr ();

      // Single Order
    singleOrder:

      int menuItems = 4;	// change as you add / remove items

      // Menu
      const char *menu[] = {
	"Burger with egg", "Burger with ham", "Cheese burger with egg", "Doule patty"	// , ... add more
      };

      // prices of menu
      const double prices[] = {
	35, 35, 40, 40		// , ... add more
      };

      title ("Single Order");

      // all options
      for (i = 0; i < menuItems; i++)
	{
	  printf (" (%d) %s : php%g\n", i + 1, menu[i], prices[i]);
	}

      // back
      printf (" (%d) Back\n", menuItems + 1);

      printPrice (totalPrice, totalItems);

      choice = askChoice ();
      if (choice < 1 || choice > menuItems + 1)
	{
	  // invalid choice
	  clrscr ();
	  invalid ();
	  goto singleOrder;
	}
      if (choice == menuItems + 1)
	{
	  // back
	  clrscr ();
	  goto mainMenu;
	}

      totalPrice += prices[choice - 1];
      totalItems += 1;

      clrscr ();
      goto singleOrder;
    }
  else if (choice == 3)
    {
      clrscr ();

      // Beverages
    beverages:

      int menuItems = 3;	// change as you add / remove items

      // Menu
      const char *menu[] = {
	"Mineral Water", "Coke", "Moutain Dew"	// , ... add more
      };

      // prices of menu
      const double prices[] = {
	15, 22, 22		// , ... add more
      };

      title ("Beverages");

      // all options
      for (i = 0; i < menuItems; i++)
	{
	  printf (" (%d) %s : php%g\n", i + 1, menu[i], prices[i]);
	}

      // back
      printf (" (%d) Back\n", menuItems + 1);

      printPrice (totalPrice, totalItems);

      choice = askChoice ();
      if (choice < 1 || choice > menuItems + 1)
	{
	  // invalid choice
	  clrscr ();
	  invalid ();
	  goto beverages;
	}
      if (choice == menuItems + 1)
	{
	  // back
	  clrscr ();
	  goto mainMenu;
	}

      totalPrice += prices[choice - 1];
      totalItems += 1;

      clrscr ();
      goto beverages;
    }


  else if (choice == 4)
    {
      clrscr ();
      title ("Check out");
      printf ("\nYour order will be arrived shortly.\n");
      printPrice (totalPrice, totalItems);
    }
  else if (choice == 5)
    {
      totalPrice = 0.0;
      totalItems = 0;
      clrscr ();
      goto mainMenu;
    }
  return 0;
}#include <stdio.h>
#include <stdlib.h>

void
clrscr ()
{
  // system("clear"); // -- linux
  system ("cls");		// -- windows
}

// printing the menu
void
printMenu (const char *title, const char **men, int len)
{
  if (title[0] != '\0')
    {
      printf ("\n---- %s ----\n", title);
    }
  // old style
  int i;
  for (i = 0; i < len; i++)
    {
      printf (" (%d) %s\n", i + 1, men[i]);
    }
  printf ("\n");
}

// number choice
int
askChoice ()
{
  int ch;
  printf ("\nChoice : ");
  scanf ("%d", &ch);
  return ch;
}

// Yes or no choice
char
YesNo ()
{
  char ch;
  printf ("\nYes / No [Y/N]: ");
  scanf (" %c", &ch);

  // convert into Yes or No..
  // y or Y => Yes, anything else => No
  if (ch != 'y' || ch != 'Y')
    {
      ch = 'N';
    }
  else if (ch == 'y')
    {
      ch = 'Y';
    }

  return ch;
}

void
divider ()
{
  printf ("\n--------------------------------\n");
}

void
title (const char *str)
{
  divider ();
  printf ("     %s", str);
  divider ();
}

void
printPrice (double totalP, int totalI)
{
  divider ();
  printf ("Total items : %d\n", totalI);
  printf ("Total price : php%g", totalP);
  divider ();
}

void
invalid ()
{
  divider ();
  printf (" Invalid choice !");
}

int
main ()
{

  // main variables
  double totalPrice = 0.0;
  int totalItems = 0;

  // change the number of mainMenuItems as you add new items to mainMenu
  int mainMenuItems = 6;
  const char *mainMenu[] = {
    "Buy 1 take 1", "Single Order", "Beverages", "Check out", "Reset", "Exit"
  };

  // don't quit right away
  int quit = 0;

  // mainMenu section
  int choice, i;
  clrscr ();			// clear screen
mainMenu:

  title ("Thai me UP");

  for (i = 0; i < mainMenuItems; i++)
    {
      printf (" (%d): %s\n", i + 1, mainMenu[i]);
    }

  printPrice (totalPrice, totalItems);

  // ask for a choice
  choice = askChoice ();

  if (choice < 1 || choice > mainMenuItems)
    {
      // invalid choice
      clrscr ();
      invalid ();
      goto mainMenu;

    }
  else if (choice == 1)
    {
      clrscr ();

      // Buy 1 take 1
    buy1take1:

    int menuItems = 3;	// change as you add / remove items

      // Menu
    const char *menu[] = {
	"Burger", "Cheese Burger", "Hotdog sandwich"	// , ... add more
      };

      // prices of menu
    const double prices[] = {
	40, 50, 50		// , ... add more
      };

    title ("Buy 1 Take 1");

      // all options
      for (i = 0; i < menuItems; i++)
	{
	  printf (" (%d) %s : php%g\n", i + 1, menu[i], prices[i]);
	}

      // back
      printf (" (%d) Back\n", menuItems + 1);

      printPrice (totalPrice, totalItems);

      choice = askChoice ();
      if (choice < 1 || choice > menuItems + 1)
	{
	  // invalid choice
	  clrscr ();
	  invalid ();
	  goto buy1take1;
	}
      if (choice == menuItems + 1)
	{
	  // back
	  clrscr ();
	  goto mainMenu;
	}

      totalPrice += prices[choice - 1];
      totalItems += 1;

      clrscr ();
      goto buy1take1;
    }
  else if (choice == 2)
    {
      clrscr ();

      // Single Order
    singleOrder:

      int menuItems = 4;	// change as you add / remove items

      // Menu
      const char *menu[] = {
	"Burger with egg", "Burger with ham", "Cheese burger with egg", "Doule patty"	// , ... add more
      };

      // prices of menu
      const double prices[] = {
	35, 35, 40, 40		// , ... add more
      };

      title ("Single Order");

      // all options
      for (i = 0; i < menuItems; i++)
	{
	  printf (" (%d) %s : php%g\n", i + 1, menu[i], prices[i]);
	}

      // back
      printf (" (%d) Back\n", menuItems + 1);

      printPrice (totalPrice, totalItems);

      choice = askChoice ();
      if (choice < 1 || choice > menuItems + 1)
	{
	  // invalid choice
	  clrscr ();
	  invalid ();
	  goto singleOrder;
	}
      if (choice == menuItems + 1)
	{
	  // back
	  clrscr ();
	  goto mainMenu;
	}

      totalPrice += prices[choice - 1];
      totalItems += 1;

      clrscr ();
      goto singleOrder;
    }
  else if (choice == 3)
    {
      clrscr ();

      // Beverages
    beverages:

      int menuItems = 3;	// change as you add / remove items

      // Menu
      const char *menu[] = {
	"Mineral Water", "Coke", "Moutain Dew"	// , ... add more
      };

      // prices of menu
      const double prices[] = {
	15, 22, 22		// , ... add more
      };

      title ("Beverages");

      // all options
      for (i = 0; i < menuItems; i++)
	{
	  printf (" (%d) %s : php%g\n", i + 1, menu[i], prices[i]);
	}

      // back
      printf (" (%d) Back\n", menuItems + 1);

      printPrice (totalPrice, totalItems);

      choice = askChoice ();
      if (choice < 1 || choice > menuItems + 1)
	{
	  // invalid choice
	  clrscr ();
	  invalid ();
	  goto beverages;
	}
      if (choice == menuItems + 1)
	{
	  // back
	  clrscr ();
	  goto mainMenu;
	}

      totalPrice += prices[choice - 1];
      totalItems += 1;

      clrscr ();
      goto beverages;
    }


  else if (choice == 4)
    {
      clrscr ();
      title ("Check out");
      printf ("\nYour order will be arrived shortly.\n");
      printPrice (totalPrice, totalItems);
    }
  else if (choice == 5)
    {
      totalPrice = 0.0;
      totalItems = 0;
      clrscr ();
      goto mainMenu;
    }
  return 0;
}