Code:
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include<stdio.h>
#include<time.h>
#include<string.h>
int booklist();
int main()
{
char passcode[8];
const char id[][8] = { "1304914", "1304961", "1304772", "1306306", "1303166","1303447" };
char title[][40] = { "Programming Vol.1 - Mr.Lim", "Programming Vol.2 - Mrs.Chooi", "Modern Physic and Wave - Mr.Lee",
"Mathematics - Mr.Kang", "Inorganic Chemistry - Mr.Alex" };
float price[6] = { 20.00f, 15.00f, 30.00f, 25.00f, 20.00f };
float ttl_1 = 0, ttl_2 = 0, ttl_3 = 0, ttl_4 = 0, ttl_5 = 0, sub_ttl = 0, grand_ttl = 0, cash_given = 0, change = 0, discount_amt = 0;
int card_type, cash_or_credit=0, book_code, menu_code, qty_1 = 0, qty_2 = 0, qty_3 = 0, qty_4 = 0, qty_5 = 0, back_main = 0, check_code, switchstart = 0, member, do_exit, back_login;
do
{
printf("\t\t\t============================= ");
printf("\n\t\t\t|| Hatsune Miku Bookstores ||");
printf("\n\t\t\t=============================\n\n");
while
((strcmp(id[0], passcode) != 0)&&
(strcmp(id[1], passcode) != 0)&&
(strcmp(id[2], passcode) != 0)&&
(strcmp(id[3], passcode) != 0)&&
(strcmp(id[4], passcode) != 0)&&
(strcmp(id[5], passcode) != 0))
{
printf("Please Enter Your 7-digit Passcode: ");
scanf(" %s[^/n]", &passcode);
if ((strcmp(id[0], passcode) !=0)&&
(strcmp(id[1], passcode) != 0)&&
(strcmp(id[2], passcode) != 0)&&
(strcmp(id[3], passcode) != 0)&&
(strcmp(id[4], passcode) != 0)&&
(strcmp(id[5], passcode) != 0)
)
{
printf("\nWrong ID Entered\n\n");
fflush(stdin);
}
}
system("cls");
do
{
back_main = 0;
if ((strcmp(id[0], passcode) == 0))
{
printf("Welcome Jojo Lim");
}
else
if ((strcmp(id[1], passcode) == 0))
{
printf("Wecome Teoh Lee Seng");
}
else
if ((strcmp(id[2], passcode) == 0))
{
printf("Welcome Ho Jia Liang");
}
else
if ((strcmp(id[3], passcode) == 0))
{
printf("Welcome Kuhan");
}
else
if ((strcmp(id[4], passcode) == 0))
{
printf("Welcome Mahen");
}
else
if ((strcmp(id[5], passcode) == 0))
{
printf("Welcome Khugganesh");
}
printf("\n\n1. Book List");
printf("\n2. Checkout");
printf("\n3. Payment");
printf("\n4. View Receipt");
printf("\n\n5. Logout");
printf("\n6. Exit");
printf("\n\n7. About This Software");
printf("\n\nPlease Enter A Code: ");
scanf("%d", &menu_code);
system("cls");
do
{
switch (menu_code)
{
case 1:
booklist();
do
{
printf("\n\nPlease Enter A Code: ");
scanf("%d", &book_code);
if (book_code == 101)
{
printf("%-32s", title[0]);
do
{
printf("\nPlease Enter the Quantity: ");
scanf("%d", &qty_1);
if (qty_1 > 0)
{
ttl_1 = (float)qty_1 * price[0];
printf("Total: RM%.2f", ttl_1);
}
else
{
printf("\nError. Invalid Code Entered. Please Enter a Number >0\n");
fflush(stdin);
}
} while (qty_1 <= 0);
}
else
if (book_code == 102)
{
printf("%-32s", title[1]);
do
{
printf("\nPlease Enter the Quantity: ");
scanf("%d", &qty_2);
if (qty_2 > 0)
{
ttl_1 = (float)qty_2 * price[1];
printf("Total: RM%.2f", ttl_2);
}
else
{
printf("\nError. Invalid Code Entered. Please Enter a Number >0\n");
fflush(stdin);
}
} while (qty_2 <= 0);
}
else
if (book_code == 103)
{
printf("%-32s", title[2]);
do
{
printf("\nPlease Enter the Quantity: ");
scanf("%d", &qty_3);
if (qty_3 > 0)
{
ttl_3 = (float)qty_3 * price[2];
printf("Total: RM%.2f", ttl_3);
}
else
{
printf("\nError. Invalid Code Entered. Please Enter a Number >0\n");
fflush(stdin);
}
} while (qty_3 < 0);
}
else
if (book_code == 104)
{
printf("%-32s", title[3]);
do
{
printf("\nPlease Enter the Quantity: ");
scanf("%d", &qty_4);
if (qty_4 > 0)
{
ttl_1 = (float)qty_4 * price[3];
printf("Total: RM%.2f", ttl_4);
}
else
{
printf("\nError. Invalid Code Entered. Please Enter a Number >0\n");
fflush(stdin);
}
} while (qty_4 <= 0);
}
else
if (book_code == 105)
{
printf("%-32s", title[4]);
do
{
printf("\nPlease Enter the Quantity: ");
scanf("%d", &qty_5);
if (qty_5 > 0)
{
ttl_1 = (float)qty_5 * price[4];
printf("Total: RM%.2f", ttl_5);
}
else
{
printf("\nError. Invalid Code Entered. Please Enter a Number >0\n");
fflush(stdin);
}
} while (qty_5 <= 0);
}
else
if (book_code == 1)
{
back_main = 1;
system("cls");
}
else
if (book_code == 2)
{
switchstart = 1;
menu_code = 2;
system("cls");
}
else
{
printf("Error. Invalid Code");
fflush(stdin);
}
} while (book_code != 1 && book_code != 2);
break;
case 2:
printf("Checkout");
printf("\n=========\n\n");
if (qty_1 > 0)
{
printf("101 - %-32s - @ RM %.2f", title[0], price[0]);
printf("\nQuantity= %d", qty_1);
printf("\nTotal= %.2f\n", ttl_1);
}
if (qty_2 > 0)
{
printf("102 - %-32s - @ RM %.2f", title[1], price[1]);
printf("\nQuantity= %d", qty_2);
printf("\nTotal= %.2f", ttl_2);
}
if (qty_3 > 0)
{
printf("103 - %-32s - @ RM %.2f", title[2], price[2]);
printf("\nQuantity= %d", qty_3);
printf("\nTotal= %.2f\n", ttl_3);
}
if (qty_4 > 0)
{
printf("104 - %-32s - @ RM %.2f", title[3], price[3]);
printf("\nQuantity= %d", qty_4);
printf("\nTotal= %.2f\n", ttl_4);
}
if (qty_5 > 0)
{
printf("105 - %-32s - @ RM %.2f", title[4], price[4]);
printf("\nQuantity= %d", qty_5);
printf("\nTotal= %.2f\n", ttl_5);
}
sub_ttl = ttl_1 + ttl_2 + ttl_3 + ttl_4 + ttl_5;
printf("\n\nSubtotal: RM %.2f", sub_ttl);
printf("\n\nEnter 1 to go to main menu, Enter 2 to proceed to payment.");
do
{
printf("\n\nAwaiting Input: ");
scanf("%d", &check_code);
if (check_code == 1)
{
back_main = 1;
switchstart = 0;
system("cls");
}
else
if (check_code == 2)
{
switchstart = 1;
menu_code = 3;
system("cls");
}
else
{
printf("\n\nError. You have entered an invalid input.\n");
fflush(stdin);
}
} while (check_code != 1 && check_code != 2);
break;
case 3:
printf("Payment");
printf("\n========");
if (sub_ttl == 0)
{
printf("\n\nError. No Item Selected for Purchase");
printf("\nPress Any Key to Return to Main Menu : ");
getch();
back_main = 1;
menu_code = 0;
switchstart = 0;
system("cls");
}
else
{
do
{
printf("\n\nAre you a member? <1 - Yes 2- No> : ");
scanf("%d", &member);
switch (member)
{
case 1:
grand_ttl = sub_ttl*(float)0.80;
printf("\n\nThere is a 20 percent discount");
break;
case 2:
grand_ttl = sub_ttl;
printf("\n\nThere is no discount");
break;
default:
printf("\nError. Invalid Code Entered");
fflush(stdin);
}
} while (member != 1 && member != 2);
printf("\n\nThe Grand Total = %.2f", grand_ttl);
while (cash_or_credit != 1 && cash_or_credit != 2)
{
printf("\n\nPay by Cash or Credit Card? <1 - Cash, 2 - Credit Card> : ");
scanf("%d", &cash_or_credit);
if (cash_or_credit == 1)
{
do
{
printf("\n\nPlease Enter Cash Tendered: RM");
scanf("%f", &cash_given);
if (cash_given >= grand_ttl)
{
change = cash_given - grand_ttl;
printf("Change: RM %.2f", change);
printf("\n\nPress any key to continue");
getch();
menu_code = 4;
switchstart = 1;
system("cls");
}
else
{
printf("Error. Invalid Input. ");
fflush(stdin);
}
} while (cash_given < grand_ttl && cash_given != grand_ttl);
}
else
if (cash_or_credit == 2)
{
printf("\n\nPlease Select Payment Card");
printf("\n1. Visa");
printf("\n2. Mastercard");
printf("\n3. American Express");
do
{
printf("\n\nSelection: ");
scanf("%d", &card_type);
if (card_type == 1 || card_type== 2 || card_type == 3)
{
menu_code = 4;
switchstart = 1;
system("cls");
}
else
{
printf("Selection Invalid. Please Try Again");
fflush(stdin);
}
} while (card_type != 1 && card_type != 2 && card_type != 3);
}
else
{
printf("Error. Invalid Input");
fflush(stdin);
}
}
}
break;
case 4:
switchstart = 0;
printf("Receipt");
printf("\n========");
printf("\n\t\t\t============================= ");
printf("\n\t\t\t|| Hatsune Miku Bookstores ||");
printf("\n\t\t\t=============================\n\n");
time_t now;
fflush(stdin);
time(&now);
printf("%s", ctime(&now));
printf("\n");
if (qty_1 > 0)
{
printf("101 - %-32s - @ RM %.2f", title[0], price[0]);
printf("\nQuantity= %d", qty_1);
printf("\nTotal= %.2f", ttl_1);
}
if (qty_2 > 0)
{
printf("102 - %-32s - @ RM %.2f", title[1], price[1]);
printf("\nQuantity= %d", qty_2);
printf("\nTotal= %.2f", ttl_2);
}
if (qty_3 > 0)
{
printf("103 - %-32s - @ RM %.2f", title[2], price[2]);
printf("\nQuantity= %d", qty_3);
printf("\nTotal= %.2f", ttl_3);
}
if (qty_4 > 0)
{
printf("104 - %-32s - @ RM %.2f", title[3], price[3]);
printf("\nQuantity= %d", qty_4);
printf("\nTotal= %.2f", ttl_4);
}
if (qty_5 > 0)
{
printf("105 - %-32s - @ RM %.2f", title[4], price[4]);
printf("\nQuantity= %d", qty_5);
printf("\nTotal= %.2f", ttl_5);
}
discount_amt = grand_ttl - sub_ttl;
printf("\n\nSubtotal: RM %.2f", sub_ttl);
printf("\nDiscount: RM %.2f", discount_amt);
if (card_type == 1)
{
printf("\nPaid by: VISA");
}
else
if (card_type == 2)
{
printf("\nPaid by: MASTER");
}
else
if ( card_type == 3)
{
printf("\nPaid by: AMEX");
}
else
{
printf("\nPaid by: CASH");
}
printf("\n====================");
printf("\nGrand Total: RM %.2f", grand_ttl);
printf("\n====================");
printf("\nCash Tendered: RM %.2f", cash_given);
printf("\nChange: RM %.2f \n\n", change);
printf("Press Any Key to Return to Main Menu :");
getch();
back_main = 1;
ttl_1 = 0;
ttl_2 = 0;
ttl_3 = 0;
ttl_4 = 0;
ttl_5 = 0;
sub_ttl = 0;
grand_ttl = 0;
cash_given = 0;
change = 0;
discount_amt=0;
card_type = 0;
cash_or_credit = 0;
menu_code = 0;
qty_1 = 0;
qty_2 = 0;
qty_3 = 0;
qty_4 = 0;
qty_5 = 0;
check_code = 0;
switchstart = 0;
member = 0;
system("cls");
break;
case 5:
back_login = 1;
passcode[0] = 0;
system("cls");
break;
case 6:
printf("Are You Sure You Want to Exit? <1 - Yes Any Key - No>\n");
scanf("%d", &do_exit);
switch (do_exit)
{
case 1: return 0;
break;
default:
back_main = 1;
system("cls");
break;
}
case 7:
printf("THIS IS A PAGE FOR ALL THE PEOPLE WHO CREATED THIS SOFTWARE WRITE WHATEVER HERE");
printf("\n\nPress Any Key to Return to Main Menu");
getch();
back_main = 1;
system("cls");
break;
default:
printf("Error. Invalid Code Entered\n\n");
fflush(stdin);
back_main = 1;
break;
}
} while (switchstart == 1);
} while (back_main == 1);
} while (back_login == 1);
return 0;
}
int booklist()
{
char title[][40] = { "Programming Vol.1 - Mr.Lim", "Programming Vol.2 - Mrs.Chooi", "Modern Physic and Wave - Mr.Lee",
"Mathematics - Mr.Kang", "Inorganic Chemistry - Mr.Alex" };
float price[6] = { 20.00f, 15.00f, 30.00f, 25.00f, 20.00f };
printf("Book List");
printf("\n==========\n\n");
printf("Code - Name - Author - Price");
printf("\n 101 - %-32s - @RM %.2f", title[0], price[0]);
printf("\n 102 - %-32s - @RM %.2f", title[1], price[1]);
printf("\n 103 - %-32s - @RM %.2f", title[2], price[2]);
printf("\n 104 - %-32s - @RM %.2f", title[3], price[3]);
printf("\n 105 - %-32s - @Rm %.2f", title[4], price[4]);
printf("\n\nEnter 1 to return to main menu, Enter 2 to proceed to checkout.");
return booklist;
}