SAMPLEEE
SAMPLEEE
h>
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
//edited2
//DECLARE FUNCTIONS
void login();//choose user or admin account
void admin_f();//admin login
void user_f();//choose user login or register account
void user_log();//user login
void user_reg();//register user account
void main_menu();//user main menu
void item_menu();//view items or buy items
void view_item();//user view items
void account_balance();//user's account balance
void change();//user change username or password
void buy_items();//user buy items
void admin_menu();//admin main menu
void manage_items();//view items and add items
void manage_acct();//view accounts
//DECLARE ARRAYS
char admin[10] = "admin";
char adminpass[10] = "1234";
char username[30][20] = {"teo", "harry", "jay", "joseph", "angel"};
char password[30][20] = {"meat", "carrot", "work", "muse", "1004"};
int money[10] = {10000, 20000, 10000, 25000, 15000};
char items[30][30] = {"Racking Chair", "Dinning Table", "Display Cabinet", "Coffee
Table", "Flower Vase "};
int price[20] = {7500, 8000, 7700, 5000, 2300};
//VARIABLES
int opt = 0, count=5, num=5, acct=0;
void main()
{
clrscr();
login();
getch();
//FUNCTIONS
void login()
{
clrscr();
if (opt==1)
{ clrscr();
user_f();
getch();
}
else if (opt==2)
{ clrscr();
admin_f();
getch();
}
else if (opt==3)
{ exit(0);
getch();
}
else { clrscr();
main();
getch();
}
getch();
void user_f()
{
clrscr();
switch (opt)
{ case 1: user_log();
break;
case 2: user_reg();
break;
case 3: login();
break;
}
getch();
void admin_f()
clrscr();
else {
cout<<"Incorrect Username/Password";
getch();
login();
}
getch();
void user_log()
{
clrscr();
}
getch();
login();
}
void user_reg()
{
clrscr();
cout<<"Password: ";
cin>>password[count];
cout<<"Account Balance: ";
cin>>money[count];
cout<<""<<endl;
cout<<"Registration Complete!"<<endl;
count++;
getch();
user_log();
void main_menu()
{
clrscr();
cout<<"WELCOME TO FURNITURE SHOP"<<endl;
cout<<""<<endl;
cout<<"MAIN MENU"<<endl;
cout<<""<<endl;
cout<<"[1] View Items"<<endl;
cout<<"[2] Account Balance"<<endl;
cout<<"[3] Change Username/Password"<<endl;
cout<<"[4] Log-out"<<endl;
cout<<""<<endl;
cout<<"Enter: "<<endl;
cin>>opt;
switch(opt)
{ case 1: item_menu();
break;
case 2: account_balance();
break;
case 3: change();
break;
case 4: login();
break;
}
getch();
void item_menu()
{
clrscr();
switch(opt)
{ case 1: buy_items();
break;
case 2: main_menu();
break;
getch();
}
void buy_items()
{
cout<<"ITEMS\t\t\t\tPRICE"<<endl;
for (int x=0; x<num; x++) {
cout<<"["<<x<<"] "<<items[x]<<"\t\t"<<price[x]<<endl;
}
cout<<""<<endl;
cout<<"Input Item No.: ";
cin>>item_num;
cout<<"Input Quantity: ";
cin>>qty;
item_price = qty*price[item_num];
cout<<""<<endl;
cout<<"Total Price: "<<item_price<<endl;;
cout<<"YOU CHECKED OUT SUCCESSFULLY!!!"<<endl;
money[acct]-=item_price;
cout<<""<<endl;
cout<<"REMAINING BALANCE DISPLAY"<<endl;
cout<<money[acct];
cout<<""<<endl;
cout<<"[press enter to exit]"<<endl;
getch();
main_menu();
}
void account_balance()
{
clrscr();
cout<<"WELCOME TO FURNITURE SHOP"<<endl;
cout<<""<<endl;
cout<<"ACCOUNT BALANCE DISPLAY"<<endl;
cout<<""<<endl;
cout<<username[acct]<<"'s current balance: "<<money[acct]<<endl;
cout<<""<<endl;
cout<<"[press enter to exit]"<<endl;
getch();
main_menu();
void change()
{
char change_user[30], change_pass[30];
clrscr();
switch(opt)
{ case 1: cout<<"WELCOME TO FURNITURE SHOP"<<endl;
cout<<""<<endl;
cout<<"CHANGE USERNAME"<<endl;
cout<<""<<endl;
for(int x=0; x<count; x++){
cout<<"Type new username: ";
cin>>username[x];
cout<<"Username successfully change!"<<endl;
cout<<"[press enter to exit]"<<endl;
getch();
change();
}
break;
getch();
void admin_menu(){
clrscr();
switch(opt)
{ case 1: manage_items();
break;
case 2: manage_acct();
break;
case 3: clrscr();
getch();
admin_menu();
break;
case 4: login();
break;
getch();
}
void manage_items(){
clrscr();
switch(opt)
{ case 1: clrscr();
case 2: clrscr();
getch();
manage_items();
break;
case 3: admin_menu();
break;
}
getch();
}
void manage_acct(){
clrscr();
switch(opt)
{ case 1: clrscr();
case 2: admin_menu();
break;
}
getch();