1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;
struct Item
{
int prod_left;
const char *name;
};
Item inventory[] = { // Each product has 100 stocks.
{ 100, "Bottled Water" },
{ 100, "Bottled Juice" },
{ 100, "Snow Cone" },
{ 100, "Iced Tea" },
{ 100, "Iced Coffee" },
{ 100, "Ice Cream" },
{ 100, "Milk Shake"},
{ 100, "Chocolate Shake" },
{ 100, "Buko Shake" },
{ 100, "Halo-Halo" },
{ 0, NULL}
};
void getSale(int &prod, int &quantity, float &price)
{
for (int i=0; inventory[i].name; ++i) {
printf("\t %d -> \t %s", i+1, inventory[i].name);
++i;
if (inventory[i].name == NULL) break;
printf("\t%d -> %s\n", i+1, inventory[i].name);
}
cout << ("\nProduct Code: ");
cin >> prod;
--prod;
printf("Quantity: ");
scanf("%d", &quantity);
printf("Price: ");
scanf("%f", &price);
inventory[prod].prod_left -= quantity;
};
void reportInventory(int prod) // Warns the user if stock is lower than 70.
{ // Also warns if stock is equak to 0, which is sold out.
if (inventory[prod].prod_left >= 70)
{
cout << "\n Products Left: " << inventory[prod].prod_left;
}
else if (inventory[prod].prod_left <= 70 && inventory[prod].prod_left >=1 )
{
cout << "\n\n\t\t============WARNING=================\nProduct Shortage: " << inventory[prod].prod_left << " products left.";
}
else if (inventory[prod].prod_left == 0)
{
printf("\n\n\t\t============WARNING=================\nProduct sold out, will be out of stock.");
}
}
int
main()
{
int trans, sum, i, e, count = 0, sales, answer;
int prod;
int quantity;
int bulk_disc;
float price;
float total_sale;
float disc_price;
float prod_left;
cout << "\t =================================================\n";
cout << "\t| |\n";
cout << "\t| W E L C O M E |\n";
cout << "\t| T O |\n";
cout << "\t| C O O L E R S |\n";
cout << "\t| |\n";
cout << "\t =================================================\n\n";
cout << "Guidline for users: \n\n\n Transaction\n\n\ 1 ->Discounted Transaction\n 2 ->Normal Transaction\n 3 ->Bulk Order Transact\
ion\n 4 ->INVENTORY\n 5 ->Record Sale";
cout << "\n\n Enter Transaction Number: ";
cin >> trans;
switch (trans)
{
case 1:
repeat:
cout << "DISCOUNTED TRANSACTION\n";
getSale(prod, quantity, price);
total_sale = quantity * price;
disc_price = total_sale - (total_sale * .20);
if (inventory[prod].prod_left < 0)
{
cout << "\nQuantity is too high, will be out of stock.";
break;
}
else if(inventory[prod].prod_left >=0)
{
printf("\nTotal product to be sold: %d", quantity);
printf("\n\nTotal price = %.2f", disc_price);
reportInventory(prod);
}
cout << "\n\nWould you like to try another transaction? [y/n]";
getline(cin, answer) >> answer;
if(answer == 'y')
{
goto repeat;
}
else if (answer == 'n')
{
cout << "Transaction finished.";
}
break;
case 2:
cout << "NORMAL TRANSACTION\n";
getSale(prod, quantity, price);
total_sale = quantity * price;
cout << "\nTotal product to be sold: " << quantity;
cout << "\n\nTotal price = %.2f" << total_sale;
reportInventory(prod);
break;
}
getch();
}
|