Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**********************************************************************************************************************
- This is to certify that this project is my own work, based on my personal efforts in studying and applying the concepts
- learned. I have constructed the functions and their respective algorithms and corresponding code by myself. The program
- was run, tested, and debugged by my own efforts. I further certify that I have not copied in part or whole or otherwise
- plagiarized the work of other students and/or persons.
- Rivera, Miguel Fernando Cua, 11610794
- **********************************************************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #define MAX_CART 100
- typedef char string15[16];
- typedef char string20[21];
- typedef char string50[51];
- typedef char string8[9];
- typedef struct {
- string20 first,middle,last;
- }nameType; //Structure for the user's name
- typedef struct{
- nameType name;
- string50 address;
- }userInfoType; //Structure for user information
- typedef struct{
- string8 code;
- int qty;
- }prodBoughtType; //Structure for the cart
- typedef struct{
- string8 productcode;
- string15 supplier,
- product;
- int quantityavailable,
- quantitysold;
- float purchaseprice,
- unitsellingprice,
- discountrate;
- }productListType; //Product List structure
- typedef struct productListType productType;
- typedef productType * ptrProduct;
- typedef struct{
- string15 category;
- ptrProduct pFirst;
- } categoryType;
- typedef categoryType aCategories[10];
- //typedef struct stockTag stockType;
- //typedef stockType * ptrStock; //Stocks Structure
- typedef prodBoughtType arrBought[MAX_CART];
- struct userTag{
- string15 username,
- password;
- userInfoType info;
- char type;
- float creditlimit,
- outstanding;
- arrBought cart;
- int nItems,
- nLocked,
- nLoggedin;
- struct userTag *pNext;
- };
- typedef struct userTag userType;
- typedef userType * ptrUser; //User Information Structure
- //Function Name: prodcode
- //Function Required Input Parameters: N/A
- //Function Expected Return Data: Product code with first letters of category, supplier and product as initial
- //Function Description and or Algorithim: obtain the first letters, concatenate, then place randomly generated numbers at end
- productType* prodcode (categoryType *pStock)
- {
- int i;
- char tempcode [3] = {0};
- char categoryinitial = (*pStock).category[0];
- char supplierinitial = (*pStock).pFirst.supplier[0];
- char productinitial = (*pStock).pFirst.product[0];
- if ((*pStock).category==NULL)
- categoryinitial = 0;
- if ((*pStock).supplier == NULL)
- supplierinitial = 0;
- if ((*pStock).pStockInfo.product == NULL)
- productinitial = 0;
- (*pStock).pStockInfo.productcode[0] = categoryinitial;
- (*pStock).pStockInfo.productcode[1] = supplierinitial;
- (*pStock).pStockInfo.productcode[2] = productinitial;
- for (i=3;i<=8;i++)
- (*pStock).pStockInfo.productcode[i] = (rand() % 10) + '0';
- for (i=0;i<2;i++){
- if ((*pStock).pStockInfo.productcode[i] > 'a' && (*pStock).pStockInfo.productcode[i] < 'z')
- (*pStock).pStockInfo.productcode[i] -= 32;
- }
- }
- //Function Name: search
- //Function Required Input Parameters: Structure pointer e.g. pUsers and a string of length 15
- //Function Expected Return Data: Address of username that is the same as the one passed to it
- //Function Description and or Algorithim: Cycle through nodes while there is still a structure. Return the address if exists, return NULL if not.
- userType* search (userType* pFirst, string15 username)
- {
- ptrUser pRun;
- pRun = pFirst;
- while (pRun != NULL && strcmp(username, pRun->username)!=0)
- pRun = pRun->pNext;
- return pRun;
- }
- //Function Name: searchStock
- //Function Required Input Parameters: Structure pointer e.g. pUsers and a string of length 15
- //Function Expected Return Data: Address of product that is the same as the one passed to it
- //Function Description and or Algorithim: Cycle through nodes while there is still a structure. Return the address if exists, return NULL if not.
- categoryType* searchStock (categoryType *pFirst, string15 product)
- {
- ptrStock pRun;
- pRun = pFirst;
- while (pRun != NULL && strcmp(product, (*pRun).pStockInfo.product)!=0)
- pRun = pRun->pNext;
- return pRun;
- }
- //Function Name: searchCategory
- //Function Required Input Parameters: Structure pointer e.g. pUsers and a string of length 15
- //Function Expected Return Data: Address of category that is the same as the one passed to it
- //Function Description and or Algorithim: Cycle through nodes while there is still a structure. Return the address if exists, return NULL if not.
- categoryType* searchCategory (categoryType *pFirst, string15 category)
- {
- ptrStock pRun;
- pRun = pFirst;
- while (pRun != NULL && strcmp(category, (*pRun).category)!=0)
- pRun = pRun->pNext;
- return pRun;
- }
- //Function Name: searchSupplier
- //Function Required Input Parameters: Structure pointer e.g. pUsers and a string of length 15
- //Function Expected Return Data: Address of supploer that is the same as the one passed to it
- //Function Description and or Algorithim: Cycle through nodes while there is still a structure. Return the address if exists, return NULL if not.
- categoryType* searchSupplier (categoryType *pFirst, string15 supplier)
- {
- ptrStock pRun;
- pRun = pFirst;
- while (pRun != NULL && strcmp(supplier, (*pRun).pStockInfo.supplier)!=0)
- pRun = pRun->pNext;
- return pRun;
- }
- //Function Name: searchProductCode
- //Function Required Input Parameters: Structure pointer e.g. pUsers and a string of length 15
- //Function Expected Return Data: Address of product code that is the same as the one passed to it
- //Function Description and or Algorithim: Cycle through nodes while there is still a structure. Return the address if exists, return NULL if not.
- /*productType* searchProductCode (categoryType *pFirst, string8 productcode)
- {
- ptrStock pRun;
- pRun = pFirst;
- while (pRun != NULL && strcmp(productcode, (*pRun).pStockInfo.productcode)!=0)
- pRun = pRun->pNext;
- return pRun;
- }
- */
- //Function Name: IsUnique
- //Function Required Input Parameters: Structure pointer e.g. pUsers and a string of length 15
- //Function Expected Return Data: 1 if the username cannot be found in the structure (if it is unique) or 0 if the username is in the function (it is not unique).
- //Function Description and or Algorithim: Cycle through nodes while there is still a structure. Return 1 or 0 depending on whether or not username was found.
- int IsUnique (userType *pUsers, string15 username)
- {
- ptrUser pRun;
- pRun = pUsers;
- while (pRun != NULL && strcmp(username, pRun->username)!=0)
- pRun = pRun->pNext;
- if (pRun == NULL)
- return 1;
- else
- return 0;
- }
- //Function Name: IsUniqueStock
- //Function Required Input Parameters: Structure pointer e.g. pUsers and a string of length 15
- //Function Expected Return Data: 1 if the product cannot be found in the structure (if it is unique) or 0 if the product is in the function (it is not unique).
- //Function Description and or Algorithim: Cycle through nodes while there is still a structure. Return 1 or 0 depending on whether or not product was found.
- int IsUniqueStock (categoryType *pStock, string15 product)
- {
- ptrStock pRun;
- pRun = pStock;
- while (pRun != NULL && strcmp (product, (*pRun).pStockInfo.product)!=0)
- pRun = pRun->pNext;
- if (pRun == NULL)
- return 1;
- else if (pRun != NULL)
- return 0;
- }
- /*
- void AdminSaveInventory (categoryType *pStock)
- {
- ptrStock pRun;
- string20 savelocation;
- char cDump;
- pRun = pStock;
- printf("Input file name where stock information will be saved. \n");
- printf("Input: ",savelocation, &cDump );
- pStock = fopen("%s.txt", "w", savelocation);
- while (pRun != NULL){
- fprintf("%s %s %s \n", pRun->category, pRun->productcode, pRun->product);
- fprintf("%d %f %s \n", pRun->quantityavailable, pRun->purchaseprice, pRun->supplier);
- fprintf("%f & % %d \n", pRun->sellingprice, pRun->discountrate, pRun->quantitysold);
- fprintf("\n");
- pRun=pRun->pNext;
- }
- }
- */
- //Function Name: AddStock
- //Function Required Input Parameters: A pointer where the new address will point to e.g. pNew and the structure pointer.
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: Adds a new stock by asking for a category, supplier, product.
- void AddStock (categoryType *pNewStock, categoryType *pStock)
- {
- int exit = 0, strikes = 0, tempinteger = 0;
- float tempfloat = 0;
- char cDump;
- do {
- printf("Input the Category: ");
- fgets(pNewStock->category,16,stdin);
- if (IsUniqueStock(pStock, pStock->category)==0)
- strikes++;
- printf("Input the Supplier: ");
- scanf("%s%c", (*pNewStock).pStockInfo.supplier, &cDump);
- if (IsUniqueStock(pStock, (*pStock).pStockInfo.supplier)==0)
- strikes++;
- printf("Input the Product Name: ");
- scanf("%s%c", (*pNewStock).pStockInfo.product, &cDump);
- if (IsUniqueStock(pStock, (*pStock).pStockInfo.product)==0)
- strikes++;
- if (strikes == 3){
- printf("This product already exists, use the Modify, Restock or add new stock with a different name \n");
- exit = 0;
- }
- printf("Input the Quantity Available for this product: ");
- scanf("%d%c", &tempinteger, &cDump);
- (*pNewStock).pStockInfo.quantityavailable = tempinteger;
- printf("Input the Purchase Price for this product: ");
- scanf("%f%c", &tempfloat, &cDump);
- (*pNewStock).pStockInfo.quantityavailable = tempfloat;
- printf("Input the Unit Selling Price for this product: ");
- scanf("%f%c", &tempfloat, &cDump);
- (*pNewStock).pStockInfo.quantityavailable = tempfloat;
- printf("Input the Discount Rate for this product: ");
- scanf("%f%c", &tempfloat, &cDump);
- (*pNewStock).pStockInfo.quantityavailable = tempfloat;
- (*pNewStock).pStockInfo.quantitysold = 0;
- prodcode (pNewStock);
- printf("Product Code of this Item: %s \n", (*pNewStock).pStockInfo.productcode);
- printf("Press [1] to add new stock or [0] to return to manage stocks menu: ");
- scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input. Returning to manage stocks menu");
- exit = 1;
- }
- }while(exit == 1);
- }
- //Function Name: AdminModifyStockMenu
- //Function Required Input Parameters: Product code of item to be modified
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: Modifies stock by asking for the product code then giving the administrator the option to modify the category, supplier, or the product name.
- void AdminModifyStockMenu (categoryType *pStock)
- {
- int choice, exit;
- char cDump;
- string8 comparecode, comparecategory, comparesupplier;
- ptrStock pRun;
- do {
- printf("Input product code of product to be modified \n");
- printf("Input: "); scanf("%s%c", comparecode, &cDump);
- while (pRun != NULL && strcmp(comparecode, (*pRun).pStockInfo.productcode)!=0)
- pRun = pRun->pNext;
- if (pRun == NULL)
- printf("Product Code not found, please try again. \n");
- printf("MODIFY STOCK INFO \n");
- printf("Product code: %s \n", (*pStock).pStockInfo.productcode);
- printf("[1] Modify Category \n");
- printf("[2] Modify Supplier \n");
- printf("[3] Modify Product \n");
- printf("[4] Modify Purchase Price \n");
- printf("[5] Modify Selling Price \n");
- printf("[6] Modify Discount \n");
- printf("[7] Finish Modifications of Product %s \n", (*pStock).pStockInfo.productcode);
- printf("[0] Return to Administrator Menu");
- printf("Input: ");
- scanf("%d%c", &choice, &cDump);
- switch (choice){
- case 1: do{
- printf("Input new category for this product: ");
- scanf("%s%c", comparecategory, &cDump);
- if (searchCategory (pStock, comparecategory)==NULL){
- printf("Category not found. Creating a new one. \n");
- strcpy(pStock->category, comparecategory);
- printf("New category for this product is %s.\n", pStock->category);
- }
- printf("Modified category for this product is %s. \n", pStock->category);
- printf("[1] Modify Category \n");
- printf("[0] Return to Modify Stocks Info Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 0;
- }
- }while(exit==1);
- break;
- case 2: do {
- printf("Input new supplier for this product: ");
- scanf("%s%c", comparesupplier, &cDump);
- if (searchSupplier (pStock, comparesupplier)==NULL){
- printf("Supplier not found. Creating a new one. \n");
- strcpy((*pStock).pStockInfo.supplier, comparesupplier);
- printf("New supplier for this product is %s.\n", pStock->category);
- }
- printf("Modified supplier for this product is %s. \n", pStock->category);
- printf("[1] Modify Supplier \n");
- printf("[0] Return to Modify Stocks Info Menu: \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 0;
- }
- }while (exit== 1);
- break;
- case 3: do {
- printf("Input new product name for this item: ");
- scanf("%s%c", comparesupplier, &cDump);
- printf("Modified product name for this product is %s. \n", pStock->category);
- printf("[1] Modify Product Name \n");
- printf("[0] Return to Modify Stocks Info Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 0;
- }
- }while (exit==1);
- break;
- case 4: do {
- printf("Input new purchase price for product: ");
- scanf("%f%c", (*pStock).pStockInfo.purchaseprice, &cDump);
- printf("New purchase price: %.2f \n", (*pStock).pStockInfo.purchaseprice);
- printf("[1] Modify Purchase Price \n");
- printf("[0] Return to Modify Stocks Info Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 0;
- }
- }while (exit == 1);
- break;
- case 5: do {
- printf("Input new selling price: ");
- scanf("%f%c", (*pStock).pStockInfo.unitsellingprice, &cDump);
- printf("New selling price: %.2f \n", (*pStock).pStockInfo.unitsellingprice);
- printf("[1] Modify Selling Price \n");
- printf("[0] Return to Modify Stocks Info Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 0;
- }
- }while (exit==1);
- break;
- case 6: do {
- printf("Input new discount: ");
- scanf("%f%c", (*pStock).pStockInfo.discountrate, &cDump);
- printf("New discount for this product: %f % ", (*pStock).pStockInfo.discountrate);
- printf("[1] Modify Selling Price \n");
- printf("[0] Return to Modify Stocks Info Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 0;
- }
- }while (exit==1);
- break;
- case 7: do {
- printf("Finishing Modification of Product.. \n");
- prodcode (pStock);
- printf("Press [0] return to main menu");
- scanf("%d", &exit);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 0;
- }
- }while (exit==1);
- break;
- default:
- break;
- }
- }while(choice > 0 && choice < 8 );
- }
- //Function Name: AdminPrepareDelivery
- //Function Required Input Parameters: The user, user info and stock structure as well as a new pointer
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: Prints out the items in the cart and their total price
- void AdminPrepareDelivery (userType *pUsers, categoryType *pStock, categoryType *pNewStock, userInfoType *pInfo)
- {
- char exit, cDump;
- ptrStock pTrail, pRun;
- ptrUser pRuns;
- float itemsubtotal, totalprice;
- do {
- pRuns = pUsers;
- if (pRun != NULL){
- printf("User ID: %s \n", pUsers->username);
- printf("Customer Name: %s, %s, %s \n", (*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
- printf("Delivery Address: %s \n", (*pInfo).address);
- printf("Product Code Product Quantity Unit Price Total Price Discount Rate Item Subtotal \n");
- //totalprice = (pUsers->cart)*(pStock->unitsellingprice);
- //itemsubtotal = (pStock->unitsellingprice) - (pStock->discountrate/100) * (pUsers->cart);
- printf("%s %s %d %f %f %f %f \n", (*pStock).pStockInfo.productcode, (*pStock).pStockInfo.product, pUsers->cart, (*pStock).pStockInfo.unitsellingprice,totalprice, (*pStock).pStockInfo.discountrate, itemsubtotal);
- }
- printf("Number of Items: %d \n");
- printf("Total Discount: Php %d \n");
- printf("Bill Amount: Php %f \n");
- printf("Total Outstanding: Php %f \n");
- pTrail = pRun;
- pRun = pRun->pNext;
- printf("[B] Previous User \n");
- printf("[N] Next User \n");
- printf("[X] Return to Manage Stocks Menu \n");
- printf("Input: "); scanf("%c%c", &exit, &cDump);
- if (exit == 'b' || exit == 'B')
- if (pTrail == NULL)
- printf("No previous user. \n");
- else
- printf("Exit function");
- }while (exit == 'B' || exit == 'b'|| exit == 'n' || exit == 'N' && (exit != 'x' || exit != 'X'));
- }
- //Function Name: AdminManageStocks
- //Function Required Input Parameters: N/A.
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: Menu where the administrator can access the stocks. Stocks can added, viewed, reordered, restocked through this menu.
- void AdminManageStocks (userType *pUsers, categoryType *pStock, categoryType *pNewStock, categoryType *pEnd)
- {
- int choice, exit, page = 0;
- char cDump, cExit = '\0';
- ptrStock pRun;
- string8 TempProdCode;
- string15 saveloc, TempCategory;
- pStock = NULL;
- pNewStock = NULL;
- pEnd = NULL;
- do {
- printf("MANAGE STOCKS MENU \n");
- printf("[1] Add New Stock \n");
- printf("[2] View All Stocks \n");
- printf("[3] View Stocks by Category \n");
- printf("[4] View Stocks to Reorder \n");
- printf("[5] Modify Stock Info \n");
- printf("[6] Restock \n");
- printf("[7] Update Inventory from File \n");
- printf("[0] Return to Administrator Menu \n");
- printf("Input: ");
- scanf("%d%c", &choice, &cDump);
- switch (choice){
- case 1: do{
- pNewStock = malloc(sizeof(categoryType));
- AddStock(pNewStock, pStock);
- pNewStock->pNext = NULL;
- if (pStock == NULL) //if initially empty
- pStock = pNewStock; //pNew is the first node
- else //connect nodes to the list
- pEnd->pNext = pNewStock;
- pEnd = pNewStock;
- }while(exit==0);
- break;
- case 2: do {
- printf("Viewing All Stocks \n");
- pRun = pStock;
- printf("Category Supplier Product Qty Available Purchase Price Selling Price Qty Sold Product Code \n");
- while (pRun != NULL && page < 20){
- printf("%s %s %s %d %f %f %d %s \n",
- pRun->category, (*pRun).pStockInfo.supplier, (*pRun).pStockInfo.product, (*pRun).pStockInfo.quantityavailable, (*pRun).pStockInfo.purchaseprice, (*pRun).pStockInfo.unitsellingprice, (*pRun).pStockInfo.quantitysold, (*pRun).pStockInfo.productcode);
- pRun = pRun->pNext;
- page++;
- }
- page = 0;
- printf("Press [N] return to main menu or ENTER to view next page. \n");
- scanf("%c%c", &cExit, &cDump);
- }while (cExit=='\0');
- break;
- case 3: do {
- printf("Input the category");
- printf("Input: ");scanf("%s%c",TempCategory, &cDump);
- searchStock (pStock, TempCategory);
- if (searchStock (pStock, TempCategory)==NULL)
- printf("Category not found \n");
- else if (searchStock (pStock, TempCategory)!=NULL)
- printf("Viewing Stocks by Category \n");
- pRun = pStock;
- printf("Category Supplier Product Quantity Available Purchase Price Unit Selling Price Quantity Sold Product Code \n");
- while (pRun != NULL){
- if (strcmp(pStock->category,TempCategory)==0){
- printf("%s %s %s %d %f %f %d %s",
- pRun->category, (*pRun).pStockInfo.supplier, (*pRun).pStockInfo.product, (*pRun).pStockInfo.quantityavailable, (*pRun).pStockInfo.purchaseprice, (*pRun).pStockInfo.unitsellingprice, (*pRun).pStockInfo.quantitysold, (*pRun).pStockInfo.productcode);
- pRun = pRun->pNext;
- }
- }
- printf("Press [0] return to main menu");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 4: do {
- printf("Viewing Stocks to Reorder \n");
- pRun = pStock;
- do{
- printf("Category Supplier Product Quantity Available Purchase Price Unit Selling Price Quantity Sold Product Code \n");
- printf("%s %s %s %d %f %f %d %s",
- pRun->category, (*pRun).pStockInfo.supplier, (*pRun).pStockInfo.product, (*pRun).pStockInfo.quantityavailable, (*pRun).pStockInfo.purchaseprice, (*pRun).pStockInfo.unitsellingprice, (*pRun).pStockInfo.quantitysold, (*pRun).pStockInfo.productcode);
- pRun = pRun->pNext;
- page++;
- }while (pRun != NULL && (*pRun).pStockInfo.quantityavailable == 0 && page < 20);
- page = 0;
- printf("Press [N] return to main menu or ENTER to view next page. \n");
- scanf("%c%c", &cExit, &cDump);
- }while (cExit=='\0');
- break;
- case 5: do {
- printf("Viewing All Stocks \n");
- pRun = pStock;
- printf("Category Supplier Product Quantity Available Purchase Price Unit Selling Price Quantity Sold Product Code \n");
- while (pRun != NULL){
- printf("%s %s %s %d %f %f %d %s",
- pRun->category, (*pRun).pStockInfo.supplier, (*pRun).pStockInfo.product, (*pRun).pStockInfo.quantityavailable, (*pRun).pStockInfo.purchaseprice, (*pRun).pStockInfo.unitsellingprice, (*pRun).pStockInfo.quantitysold, (*pRun).pStockInfo.productcode);
- pRun = pRun->pNext;
- }
- printf("Modify Stock Info \n");
- AdminModifyStockMenu(pStock);
- printf("Press [0] return to main menu");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 6: do {
- printf("Restock \n");
- pRun = pStock;
- printf("Category Supplier Product Quantity Available Purchase Price Unit Selling Price Quantity Sold Product Code \n");
- while (pRun != NULL){
- printf("%s %s %s %d %f %f %d %s",
- pRun->category, (*pRun).pStockInfo.supplier, (*pRun).pStockInfo.product, (*pRun).pStockInfo.quantityavailable, (*pRun).pStockInfo.purchaseprice, (*pRun).pStockInfo.unitsellingprice, (*pRun).pStockInfo.quantitysold, (*pRun).pStockInfo.productcode);
- pRun = pRun->pNext;
- }
- printf("Input the product code of the product that will be restocked: ");
- scanf("%s%c",TempProdCode, &cDump);
- pRun = pStock;
- while (pRun != NULL && strcmp(TempProdCode, (*pRun).pStockInfo.productcode)!=0){
- pRun = pRun->pNext;
- if (pRun == NULL){
- printf("Last input product code not found. Not restocked. Returning to Manage Stocks Menu \n");
- exit = 0;
- }
- if (pRun != NULL && strcmp(TempProdCode, (*pRun).pStockInfo.productcode)==0){
- printf("Additional Quantity for this item: ");
- scanf("%d%c", (*pRun).pStockInfo.quantityavailable, &cDump);
- printf("This product has been restocked and has %d quantity available. \n", (*pRun).pStockInfo.quantityavailable);
- }
- }
- printf("Press [0] return to main menu");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 7: do {
- printf("Input save location: ");
- scanf("%s%c", saveloc, &cDump);
- printf("Press [0] return to main menu");
- scanf("%d", &exit);
- }while (exit==1);
- break;
- default: choice = 0;
- break;
- }
- }while(choice > 0 && choice < 9 );
- }
- //Function Name: AdminManageAccounts
- //Function Required Input Parameters: N/A
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: Menu where administrator can access the shopper accounts registered in the kiosk. Here the administrator can unlock certain users or unlock all, as well as view those with outstanding.
- void AdminManageAccounts (userType *pUsers, userInfoType *pInfo)
- {
- int choice = 0, exit;
- char cDump, yesorno;
- string15 CompareUser;
- userType *pLock;
- ptrUser pRun;
- pRun = pUsers;
- do {
- printf("Welcome, %s, %s, %s. \n",(*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
- printf("MANAGE ACCOUNTS MENU \n");
- printf("[1] View Locked Accounts \n");
- printf("[2] Unlock Specific Account \n");
- printf("[3] Unlock All Locked Accounts \n");
- printf("[4] View Accounts with Outstanding Balance \n");
- printf("[0] Return to Administrator Menu \n");
- printf("Input: ");
- scanf("%d%c", &choice, &cDump);
- switch (choice) {
- case 1: do {
- while (pRun != NULL && pUsers->nLocked == 1){
- pRun = pRun->pNext;
- printf("Username: %s \n", pRun->username);
- printf("Name: %s, %s ,%s",(*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
- if (pRun->username == NULL)
- printf("No account is locked. \n");
- }
- printf("[0] Return to Manage Accounts Menu \n");
- printf("[1] View All Locked Accounts \n");
- printf("Input: ");scanf("%d", &exit);
- if(exit>1||exit<0)
- {
- printf("Invalid input. Returning to Manage Accounts Menu \n");
- exit = 1;
- }
- } while(exit == 1);
- pRun = NULL;
- free(pRun);
- break;
- case 2: do {
- printf("Input username of locked account. \n");
- printf("Input: ");scanf("%s%c", CompareUser, &cDump);
- pLock = search (pUsers, CompareUser);
- if (pLock != NULL)
- pLock->nLocked = 0;
- printf("[0] Return to Manage Accounts Menu \n");
- printf("[1] Unlock Another Account\n");
- printf("Input: ");scanf("%d", &exit);
- if(exit>1||exit<0)
- {
- printf("Invalid input. Returning to Manage Accounts Menu \n");
- exit = 1;
- }
- } while(exit == 1);
- break;
- case 3: do {
- printf("Would you like to unlock all locked accounts? [Y]es | [N]o \n");
- scanf("%c%c",&yesorno, &cDump);
- if (yesorno == 'y' || yesorno == 'Y'){
- while (pRun != NULL ){
- if (pRun->nLocked == 1)
- pRun->nLocked = 0;
- pRun = pRun->pNext;
- }
- }
- printf("[0] Return to Manage Accounts Menu \n");
- printf("Input: ");scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input. Returning to Manage Accounts Menu \n");
- exit = 1;
- }
- } while(exit == 1);
- break;
- case 4: do {
- printf("Diplaying Accounts with Outstanding Balance \n");
- while (pRun != NULL){
- if (pRun->outstanding>0){
- printf("%s \n", pRun->username);
- printf("%s \n", (*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
- printf("%f \n", pRun->outstanding);
- }
- }
- printf("[0] Return to Manage Accounts Menu \n");
- printf("Input: ");scanf("%d", &exit);
- if(exit>1||exit<0)
- {
- printf("Invalid input. Returning to Manage Accounts Menu \n");
- exit = 1;
- }
- }while (exit == 1);
- break;
- default: printf("Returning to Administrator Menu.. \n");
- break;
- }
- } while (choice > 0 && choice < 5);
- }
- //Function Name: SignUp
- //Function Required Input Parameters: Username and Password of account to be made. Authorization code if administrator account is to be made by user.
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: Menu where administrator can access the shopper accounts registered in the kiosk. Here the administrator can unlock certain users or unlock all, as well as view those with outstanding.
- void signUp (userType *pUser, userType *pUsers)
- {
- int unique = 0;
- char cDump, choice, cTempType = '\0';
- char arrInputCode[9];
- char arrCompareCode[9] = {"DLSU2017"};
- string15 TempUsername;
- do{
- printf("Enter username: ");
- scanf("%s%c", (*pUser).username /*TempUsername*/,&cDump); //placing the information directly within the container. Username is inside pUser
- if (IsUnique (pUsers, pUser->username) == 0){
- printf("Username taken, please input a unique username. \n");
- unique = 0;
- }
- else if (IsUnique (pUsers, pUser->username) == 1){
- unique = 1;
- printf("Username is unique, proceeding. \n");
- }
- }while (strlen((*pUser).username)<3 || strlen((*pUser).username)>15 || unique != 1);
- do{
- printf("Enter password: ");
- scanf("%s%c", (*pUser).password,&cDump); //placing the information directly within the container. Username is inside pUser
- if (strlen((*pUser).password)<6){
- printf("Password too short, please try again. \n");
- printf("Enter password: ");
- scanf("%s%c", (*pUser).password,&cDump);
- }
- if (strlen((*pUser).password)>15){
- printf("Password too long, please try again. \n");
- printf("Enter password: ");
- scanf("%s%c", (*pUser).password,&cDump);
- }
- if (ValidPass(pUser)==1)
- printf("Password is valid. \n");
- else{
- printf("Error, password must contain non-letter character.\n");
- printf("Enter password: ");
- scanf("%s%c", (*pUser).password,&cDump);
- }
- }while (strlen((*pUser).password)<6 || strlen((*pUser).password)>15);
- printf("Create [S]hopper or [A]dministrator account? \n");
- printf("Input: ");
- scanf("%c%c", &cTempType, &cDump);
- if(cTempType != 's' && cTempType != 'S' && cTempType != 'a' && cTempType != 'A'){
- printf("Invalid input, please try again: \n");
- while (cTempType != 's' && cTempType != 'S' && cTempType != 'a' && cTempType != 'A'){
- printf("Input: ");
- scanf("%c%c",&cTempType, &cDump);
- }
- }
- if (cTempType == 's' || cTempType == 'S'){
- (*pUser).type = 'S';
- printf("Account Type: Shopper \n");
- (*pUser).creditlimit = 5000.00;
- printf("Your current Credit Limit is Php 5000.00. \n");
- (*pUser).outstanding = 0.00;
- printf("Your current Outstanding Balance is Php 0.00. \n");
- }
- else if (cTempType == 'a' || cTempType == 'A'){
- do {
- printf("Input authorization code: ");
- scanf("%s%c", arrInputCode,&cDump);
- if (strcmp(arrInputCode,arrCompareCode)==0){
- (*pUser).type = 'A';
- //AdminChoice();
- printf("Account Type: Admin \n");
- }
- else
- printf("Invalid authorization code, try again. Please try again. \n");
- }while (strcmp(arrInputCode,arrCompareCode)!=0);
- }
- }
- /*void capitalize (userType *pUsers, userInfoType *pInfo)
- {
- char arrTemp[16];
- if ((*pInfo).name.first[1] > 'a' || (*pInfo).name.first[1] < 'z' )
- (*pInfo).name.first[1] -= 32;
- }
- */
- //Function Name: modifyUserInfo
- //Function Required Input Parameters: N/A
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: Menu where shopper can access the information of his account and change them if needed.
- void modifyUserInfo (userType *pUser, userInfoType *pInfo)
- {
- int choice = 0, exit = 0;
- char cDump;
- char arrComparePass[16];
- do {
- printf("Hello, %s, %s, %s. \n",(*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
- printf("What would you like to change? \n");
- printf("[1] Change Name \n");
- printf("[2] Change Address \n");
- printf("[3] Change Password \n");
- printf("[0] Return to Shopper Menu \n");
- printf("Input: ");
- scanf("%d%c", &choice, &cDump);
- switch (choice) {
- case 1: do {
- printf("Change First Name: ");
- fgets((*pInfo).name.first,21,stdin);
- if ((*pInfo).name.first[0] > 'a' && (*pInfo).name.first[0] < 'z' )
- (*pInfo).name.first[0] -= 32;
- printf("Change Middle Name: ");
- fgets((*pInfo).name.middle,21,stdin);
- if ((*pInfo).name.middle[0] > 'a' && (*pInfo).name.middle[0] < 'z' )
- (*pInfo).name.middle[0] -= 32;
- printf("Change Last Name: ");
- fgets((*pInfo).name.last,51,stdin);
- if ((*pInfo).name.last[0] > 'a' && (*pInfo).name.last[0] < 'z' )
- (*pInfo).name.last[0] -= 32;
- printf("Your new name is: %s,%s,%s \n", (*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
- printf("[0] Return to Modify User Info Menu \n");
- printf("[1] Reinput Name \n");
- printf("Input: ");scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 1;
- }
- } while(exit == 1);
- break;
- case 2: do {
- printf("Input your new Address: ");
- fgets((*pInfo).address,51,stdin);
- (*pInfo).address[strlen((*pInfo).address)-1]='\0';
- printf("Your new Address is: %s \n",(*pInfo).address);
- printf("[0] Return to Modify User Info Menu \n");
- printf("[1] Reinput Address\n");
- printf("Input: ");scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 1;
- }
- } while(exit == 1);
- break;
- case 3: do {
- while (strcmp((*pUser).password, arrComparePass)!=0){
- printf("Input your current password. \n");
- scanf("%s%c",arrComparePass,&cDump);
- if(strcmp((*pUser).password, arrComparePass)!=0){
- printf("Password does not match, please try again. \n");
- printf("Input: "); scanf("%s%c", arrComparePass,&cDump);
- }
- }
- printf("Input your new Password: ");
- scanf("%s%c", (*pUser).password,&cDump); //placing the information directly within the container. Username is inside pUser
- if (strlen((*pUser).password)<6){
- printf("Password too short, please try again. \n");
- printf("Enter password: ");
- scanf("%s%c", (*pUser).password,&cDump);
- }
- if (strlen((*pUser).password)>15){
- printf("Password too short, please try again. \n");
- printf("Enter password: ");
- scanf("%s%c", (*pUser).password,&cDump);
- }
- if (ValidPass(pUser)==1)
- printf("Password is valid. \n");
- else{
- printf("Error, password must contain non-letter character.\n");
- printf("Enter password: ");
- scanf("%s%c", (*pUser).password,&cDump);
- }
- printf("Your new Password is %s. \n", (*pUser).password);
- printf("[0] Return to Modify User Info Menu \n");
- printf("[1] Reinput Address\n");
- printf("Input: ");scanf("%d", &exit);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 1;
- }
- } while(exit == 1);
- break;
- default: choice = 0;
- }
- } while (choice == 1 || choice == 2 || choice == 3);
- }
- //Function Name: getUserInfo
- //Function Required Input Parameters: User's whole name and address
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: To be done after signUp function, user is prompted to enter their name and address.
- void getUserInfo (userInfoType *pInfo)
- {
- printf("Enter name: \n");
- printf("First Name: ");
- fgets((*pInfo).name.first,21,stdin);
- if ((*pInfo).name.first[0] > 'a' && (*pInfo).name.first[0] < 'z' )
- (*pInfo).name.first[0] -= 32;
- printf("Middle Name: ");
- fgets((*pInfo).name.middle,21,stdin);
- if ((*pInfo).name.middle[0] > 'a' && (*pInfo).name.middle[0] < 'z' )
- (*pInfo).name.middle[0] -= 32;
- printf("Last Name: ");
- fgets((*pInfo).name.last,51,stdin);
- if ((*pInfo).name.last[0] > 'a' && (*pInfo).name.last[0] < 'z' )
- (*pInfo).name.last[0] -= 32;
- printf("%s,%s,%s \n", (*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
- printf("Enter address: ");
- fgets((*pInfo).address,51,stdin);
- (*pInfo).address[strlen((*pInfo).address)-1]='\0';
- (*pInfo).name.first[strlen((*pInfo).name.first)-1]='\0';
- (*pInfo).name.middle[strlen((*pInfo).name.middle)-1]='\0';
- (*pInfo).name.last[strlen((*pInfo).name.last)-1]='\0';
- }
- //Function Name: getUserInfo
- //Function Required Input Parameters: N/A (Is passed the password)
- //Function Expected Return Data: 1 or 0 depending on whether or not the password is valid.
- //Function Description and or Algorithim: Checks whether or not there is a non-character present in the password.
- int ValidPass (userType *pUser)
- {
- int i, valid=0;
- for(i=0;i<(strlen(pUser->password));i++){
- if (pUser->password[i] < 'a' || pUser->password[i] >'z')
- if (pUser->password[i] < 'A' || pUser->password[i] >'Z')
- valid=1;
- }
- return valid;
- }
- //Function Name: displayAll
- //Function Required Input Parameters: N/A
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: Displays all users registered in the kiosk.
- void displayAll (userType *pUsers)
- {
- while (pUsers!=NULL){ //stop traversing when there is no more new address
- printf("%s\n", pUsers->username);
- pUsers = pUsers->pNext; //node traversal
- }
- }
- //Function Name: signIn
- //Function Required Input Parameters: Unique username and password
- //Function Expected Return Data: 1 or 2 depending on account type.
- //Function Description and or Algorithim: Logs-in the user. If is an administrator, asks for authorization code.
- int signIn (userType *pUsers, userInfoType *pInfo, userType *pNew, userType *pLast)
- {
- int loggedin=0, tries=3, exit = 0, AccountType = 0;
- char arrTempUser[16], arrTempPW[16], arrInputCode[9], authcode[9]={"DLSU2017"};
- char cDump;
- userType *pLogin, *pPassword;
- do{
- printf("Enter username: ");
- scanf("%s", arrTempUser);fflush(stdin);
- printf("Enter password: ");
- scanf("%s", arrTempPW);fflush(stdin);
- if(pUsers!=NULL)
- {
- pLogin = search(pUsers, arrTempUser);
- pPassword = search(pUsers, pUsers->username);
- if (pLogin == NULL){
- printf("Not found address\n");
- signIn (pUsers, pInfo, pNew, pLast);
- }
- }
- else if (pUsers == NULL)
- {
- printf("Not found was null\n");
- signIn (pUsers, pInfo, pNew, pLast);
- }
- if (pUsers->nLocked == 1)
- printf("This account is locked, contact an administrator, returning to main menu. \n");
- if (strcmp(pLogin->username, arrTempUser)==0){
- if (strcmp(pPassword->password, arrTempPW)==0){
- pUsers->nLoggedin = 1;
- }
- else{
- while (strcmp(pPassword->password, arrTempPW)!=0 && pUsers->nLocked != 1){
- printf("Incorrect password, please try again. %d tries remaining: \n", tries);
- tries--;
- scanf("%s%c", arrTempPW, &cDump);
- if (tries == 0){
- printf("This account has been locked. Contact Administrator. Returning to main menu. \n");
- pUsers->nLocked = 1;
- exit = 1;
- }
- }
- }
- }
- else {
- printf("Incorrect username or password, please try again. %d tries remaining: \n", tries);
- printf("%s", arrTempUser);
- printf("%d", strcmp(pLogin->username, arrTempUser));
- tries--;
- }
- if (pUsers->type == 'A' && pUsers->nLocked == 0){
- printf("Input authorization code: ");
- scanf("%s%c", arrInputCode, &cDump);
- if (strcmp(arrInputCode,authcode)==0){
- AccountType = 2;
- pUsers->nLoggedin = 1;
- loggedin = 1;
- exit = 1;
- return AccountType;
- }
- else{
- while (strcmp(arrInputCode,authcode)!=0){
- printf("Incorrect code, please try again.\n");
- printf("Input: "); scanf("%s%c", arrInputCode, &cDump);
- }
- }
- }
- else if (pUsers->type == 'S' && pUsers->nLocked == 0){
- printf("Welcome, %s \n", (*pInfo).name.first);
- //pUsers->loggedin = 1;
- //modifyUserInfo (pUsers, pInfo);
- AccountType = 1;
- return AccountType;
- pUsers->nLoggedin = 1;
- }
- }while (loggedin == 0 && tries > 0 && exit == 0 && pUsers->nLocked != 1);
- }
- void freeAll (ptrUser *pFirst)
- {
- userType *pDel;
- while(*pFirst != NULL){
- pDel = *pFirst;
- *pFirst = (*pFirst)->pNext;
- free(pDel);
- }
- }
- //Function Name: ShopperMenu
- //Function Required Input Parameters: N/A
- //Function Expected Return Data: N/A
- //Function Description and or Algorithim: Displays the menu for the shopper accessing the kiosk.
- void ShopperMenu (userType *pUsers, userType *pNew, userType *pLast, userInfoType *pInfo, categoryType *pStock)
- {
- int choice = 0, page = 20;
- char cDump, cExit = '\0';
- int exit;
- string15 TempCategory;
- ptrStock pRun;
- do {
- printf("SHOPPER MENU \n");
- printf("[1] Modify User Info \n");
- printf("[2] Browse All Products \n");
- printf("[3] Browse Products by Category \n");
- printf("[4] Browse Products on Sale \n");
- if (pUsers->outstanding > 0);
- printf("[5] Add to Cart \n");
- if (pUsers->cart)
- printf("[6] View Cart \n");
- printf("[7] Check Out \n");
- printf("[8] Edit Cart Items \n");
- printf("[0] Return to Main Menu \n");
- printf("Input: ");
- scanf("%d%c", &choice, &cDump);
- switch (choice){
- case 1: do {
- modifyUserInfo (pUsers, &pUsers->info);
- printf("Press [0] to Return to Shopper Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- //view locked
- break;
- case 2: do {
- printf("Browsing All Products \n");
- pRun = pStock;
- printf("Category Brand Product Code Product Quantity Available Quantity Sold Unit Price Discount Rate \n");
- while (pRun != NULL && page < 20){
- if ((*pRun).pStockInfo.quantityavailable > 1){
- printf("%s %s %s %s %d %d %f %f \n",
- (*pRun).category, (*pRun).pStockInfo.supplier, (*pRun).pStockInfo.productcode, (*pRun).pStockInfo.product, (*pRun).pStockInfo.quantityavailable, (*pRun).pStockInfo.quantitysold, (*pRun).pStockInfo.unitsellingprice, (*pRun).pStockInfo.discountrate);
- }
- pRun = pRun->pNext;
- page++;
- }
- page = 0;
- printf("Press [N] return to main menu or ENTER to view next page. \n");
- scanf("%c%c", &cExit, &cDump);
- }while (cExit=='\0');
- break;
- case 3: do {
- printf("Input the category");
- printf("Input: ");scanf("%s%c",TempCategory, &cDump);
- searchStock (pStock, TempCategory);
- if (searchStock (pStock, TempCategory)==NULL)
- printf("Category not found \n");
- else if (searchStock (pStock, TempCategory)!=NULL){
- printf("Browsing Products by Category \n");
- pRun = pStock;
- printf("Category Brand Product Code Product Quantity Available Quantity Sold Unit Price Discount Rate \n");
- while (pRun != NULL){
- if (strcmp(pRun->category,TempCategory)==0 && (*pRun).pStockInfo.quantityavailable>1){
- printf("%s %s %s %s %d %d %f %f \n",
- (*pRun).category, (*pRun).pStockInfo.supplier, (*pRun).pStockInfo.productcode, (*pRun).pStockInfo.product, (*pRun).pStockInfo.quantityavailable, (*pRun).pStockInfo.quantitysold, (*pRun).pStockInfo.unitsellingprice, (*pRun).pStockInfo.discountrate);
- }
- pRun = pRun->pNext;
- }
- }
- printf("Press [0] to Return to Shopper Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 4: do {
- printf("Browsing Products on Sale \n");
- pRun = pStock;
- while (pRun != NULL)
- {
- if ((*pRun).pStockInfo.discountrate > 0){
- printf("%s %s %s %s %d %d %f %f \n",
- (*pRun).category, (*pRun).pStockInfo.supplier, (*pRun).pStockInfo.productcode, (*pRun).pStockInfo.product, (*pRun).pStockInfo.quantityavailable, (*pRun).pStockInfo.quantitysold, (*pRun).pStockInfo.unitsellingprice, (*pRun).pStockInfo.discountrate);
- }
- pRun = pRun->pNext;
- }
- printf("Press [0] to Return to Shopper Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 5: do {
- printf("Input the product code of the item: \n");
- printf("Press [0] to Return to Shopper Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 6: do {
- printf("Viewing Cart \n");
- printf("Press [0] to Return to Shopper Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 7: do {
- printf("Press [0] to Return to Shopper Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 8: do {
- printf("Press [0] to Return to Shopper Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- default: printf("Your account has been successfully logged out. \n");
- pUsers->nLoggedin = 0;
- choice = 0;
- break;
- }
- }while (choice > 0 && choice < 9);
- }
- //Function Name: AdminMenu
- //Function Required Input Parameters: N/A
- //Function Expected Return Data: 0 if the administrator wishes to shutdown the kiosk
- //Function Description and or Algorithim: Displays the administrator menu so the administrator can access the aspects of the kiosk.
- int AdminMenu (userType *pUsers, userType *pNew, userType *pLast, userInfoType *pInfo, categoryType *pStock, categoryType *pNewStock, categoryType *pEnd)
- {
- int choice, exit = 1;
- char cDump;
- do {
- printf("ADMINISTRATOR MENU \n");
- printf("[1] Manage Accounts Menu \n");
- printf("[2] Manage Stocks Menu \n");
- printf("[3] Prepare Delivery Receipt \n");
- printf("[4] Shutdown Kiosk \n");
- printf("[5] Log Out \n");
- printf("Input: ");
- scanf("%d%c", &choice, &cDump);
- switch (choice){
- case 1: do {
- AdminManageAccounts (pUsers, &pUsers->info);
- printf("Press [0] to return to Administrator Menu: ");
- scanf("%d", &exit);
- }while (exit==1);
- break;
- case 2: do {
- AdminManageStocks (pUsers, pStock, pNewStock, pEnd);
- printf("Press [0] to return to Administrator Menu: ");
- scanf("%d", &exit);
- }while (exit==1);
- break;
- case 3: do {
- AdminPrepareDelivery (pUsers, pStock, pNewStock, &pUsers->info);
- printf("Press [0] to return to Administrator Menu: ");
- scanf("%d", &exit);
- }while (exit==1);
- break;
- case 4:
- printf("Kiosk Shutdown. \n");
- choice = 0;
- return 0;
- break;
- case 5:
- pUsers->nLoggedin == 0;
- printf("Your account has been successfully logged out. \n");
- break;
- default:
- break;
- }
- }while (choice > 0 && choice < 5 && choice != 4);
- }
- //Function Name: menu
- //Function Required Input Parameters: N/A
- //Function Expected Return Data: 0 if the user wishes to shutdown kiosk
- //Function Description and or Algorithim: Displays the sign up and login for the user to access.
- void menu (userType *pUsers, userType *pNew, userType *pLast, categoryType *pStock, categoryType *pNewStock, categoryType *pEnd)
- {
- int choice=0;
- char cDump;
- int exit;
- pUsers = NULL;
- pNew = NULL;
- pLast = NULL;
- ptrUser pRun, pTrail;
- do {
- printf("MAIN MENU \n");
- printf("[1] Sign Up \n");
- printf("[2] Log In \n");
- //printf("[0] Shutdown Kiosk \n");
- printf("Choice: ");
- scanf("%d%c", &choice,&cDump);
- if (choice > 2 || choice < 0 ){
- printf("INVALID INPUT \n \n");
- menu (pUsers, pNew, pLast, pStock, pNewStock, pEnd);
- }
- switch (choice){
- case 1:
- do{
- pNew = malloc(sizeof(userType));
- signUp(pNew, pUsers);
- pNew -> pNext = NULL;
- if (pUsers == NULL) //if list is empty
- pUsers = pNew;
- else if (strcmp(pUsers -> username, pNew -> username) > 0){ //conect as first node
- pNew -> pNext = pUsers;
- pUsers = pNew;
- }
- else { //modifying middle of list
- pRun = pUsers;
- while (pRun != NULL && strcmp(pRun -> username, pNew -> username) < 0){
- pTrail = pRun;
- pRun = pRun -> pNext;
- }
- pTrail -> pNext = pNew;
- pNew -> pNext = pRun;
- }
- getUserInfo (&pUsers->info);
- printf("Press [0] to create a new user or [1] to return to main menu: ");
- scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 1;
- }
- }while(exit==0);
- break;
- case 2:
- if (signIn(pUsers, &pUsers->info , pNew, pLast)==1)
- ShopperMenu (pUsers, pNew, pLast, &pUsers->info, pStock);
- else if (signIn(pUsers, &pUsers->info , pNew, pLast)==2)
- if (AdminMenu (pUsers, pNew, pLast, &pUsers->info, pStock, pNewStock, pEnd)==0)
- choice = 0;
- break;
- default:freeAll(&pUsers);
- break;
- }
- }while (choice == 1||choice == 2);
- freeAll(&pUsers);
- }
- int main ()
- {
- categoryType *pFirst,
- *pNewStock,
- *pEnd;
- userType *pUsers,
- *pNew,
- *pLast;
- ptrUser pRun, pTrail;
- categoryType aCategories[10];
- menu (pUsers, pNew, pLast, pFirst, pNewStock, pEnd);
- //displayAll(pUsers);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement