Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
2.2 kB
2
Indexable
Never
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <cstdlib>
#include <stdlib.h>

using namespace std;

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;

void gotoXY(int, int);

int main()
{
	string id, name;
	int menu_item = 0, run, x = 7, quantity = 0;
	double price = 0.00;
	bool running = true;

	gotoXY(18, 5); cout << "Main Menu";
	gotoXY(18, 7); cout << ">";

	while (running)
	{
		gotoXY(10, 7);  cout << "[1] - ADD ITEM";
		gotoXY(10, 8);  cout << "[2] - SEARCH ITEM";
		gotoXY(10, 9);  cout << "[3] - DELETE ITEM";
		gotoXY(10, 10); cout << "[4] - SHOW ITEM LIST";
		gotoXY(10, 11); cout << "[5] - BACK TO MENU";

		system("pause>nul");

		if (GetAsyncKeyState(VK_DOWN) && x != 11) //down button pressed
		{
			gotoXY(8, x); cout << "  ";
			x++;
			gotoXY(8, x); cout << ">";
			menu_item++;
			continue;
		}

		if (GetAsyncKeyState(VK_UP) && x != 7) //up button pressed
		{
			gotoXY(8, x); cout << "  ";
			x--;
			gotoXY(8, x); cout << ">";
			menu_item--;
			continue;
		}

		if (GetAsyncKeyState(VK_RETURN)) { // Enter key pressed

			switch (menu_item) {

			case 0: {
				system("CLS");
				char save;
				gotoXY(10, 7);
				cout << "ID: ";
				cin >> id;
				gotoXY(10, 8);
				cout << "NAME: ";
				cin >> name;
				gotoXY(10, 9);
				cout << "PRICE: ";
				cin >> price;
				gotoXY(10, 10);
				cout << "QUANTITY: ";
				cin >> quantity;
				gotoXY(10, 11);
				cout << "SAVE THE RECORD (y/n)? ";
				cin >> save;
				gotoXY(10, 12);
				if (save == 'y') {
					break;
				}
				else {
					break;
				}
			}


			case 1: {
				gotoXY(10, 16);
				cout << "SEARCH ITEM     ";
				break;
			}

			case 2: {
				gotoXY(10, 16);
				cout << "DELETE ITEM     ";
				break;
			}

			case 3: {
				gotoXY(10, 16);
				cout << "SHOW ITEM LIST     ";
				break;
			}

			case 4: {
				gotoXY(10, 16);
				cout << "BACK TO MENU";
				break;
			}

			}

		}

	}

	gotoXY(20, 21);
	return 0;
}

void gotoXY(int x, int y)
{
	CursorPosition.X = x;
	CursorPosition.Y = y;
	SetConsoleCursorPosition(console, CursorPosition);
}