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.
- Alexandra Rotor Reyes, DLSU ID# 11622105
- **********************************************************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #define MAX_ITEMS 100
- typedef char string8[9];
- typedef char string15[16];
- typedef char string20[21];
- typedef char string50[51];
- /* structures needed for the program */
- typedef struct
- {
- string20 first,
- middle,
- last;
- } nameType;
- typedef struct
- {
- nameType name;
- string50 address;
- } userInfoType;
- typedef struct
- {
- string8 code;
- int qty;
- } prodBoughtType;
- typedef prodBoughtType arrBought[MAX_ITEMS];
- /* linked list about the user */
- typedef struct aboutUser
- {
- string15 username,
- password;
- userInfoType info;
- int type; /* administrator or shopper? */
- float creditLimit,
- outstanding;
- arrBought cart;
- int nItems,
- isLocked;
- struct aboutUser *next;
- } userNode;
- /* linked list about the stocks */
- typedef struct aboutStock
- {
- string8 pCode;
- string15 supplier,
- product;
- int avbl,
- sold;
- float purchasePrice,
- sellingPrice,
- discountRate;
- struct aboutStock *next;
- } stockNode;
- /* linked list about the category */
- typedef struct categ
- {
- string15 category;
- stockNode productInfo;
- struct categ *next;
- } categNode;
- /*
- FUNCTION: viewLocked allows the administrator to see all locked accounts
- @param: userNode *user: structure with user information
- @return: void
- */
- void viewLocked (userNode *user)
- {
- int ctr=1;
- userNode *temp=NULL;
- temp=user;
- printf("\nView Locked Accounts:\n");
- do
- {
- if (temp->isLocked==1 && temp->type==2)
- {
- printf("Account #%d: %s\n", ctr, temp->username);
- printf("Name: %s, %s %s\n", temp->info.name.last, temp->info.name.first, temp->info.name.middle);
- }
- else
- {
- printf("No locked accounts!\n");
- break;
- }
- temp=temp->next;
- ctr++;
- } while (temp!=NULL);
- }
- /*
- FUNCTION: unlockSpecific allows the admin to unlock a specific account by selecting
- which account to unlock
- @param: userNode *user: structure with user information
- @return: void
- */
- void unlockSpecific (userNode *user)
- {
- string15 iUser;
- userNode *temp=NULL;
- int compare=2, choice=0, close=0;
- temp=user;
- printf("\nUnlock a specific account: \n");
- do
- {
- printf("Enter username of the account you wish to unlock: \n");
- scanf("%s", iUser);
- compare=strcmp(iUser, temp->username);
- do
- {
- if (temp->isLocked==1 && compare==0)
- {
- temp->isLocked=0;
- temp=temp->next;
- }
- } while (temp!=NULL);
- printf("Account has been unlocked.\n");
- printf("Would you like to unlock another user? \n");
- printf("1. Yes\n");
- printf("2. No\n");
- do
- {
- switch (choice)
- {
- case 1: close=0;
- break;
- case 2: close=1;
- break;
- default: printf("Invalid input. Try again.\n");
- }
- } while (choice!=1 && choice!=2);
- } while (close==1);
- }
- /*
- FUNCTION: unlockAll allows the admin to unlock all the accounts
- @param: userNode *user: structure with user information
- @return: void
- */
- void unlockAll (userNode *user)
- {
- userNode *temp=NULL;
- temp=user;
- printf("\nUnlock all accounts: \n");
- printf("Loading...\n");
- while (temp!=NULL)
- {
- if (temp->isLocked==1)
- temp->isLocked=0;
- temp=temp->next;
- }
- printf("All accounts have been unlocked!\n");
- }
- /*
- FUNCTION: viewOutBal allows the admin to check which users have outstanding balance
- @param: userNode *user: structure with user information
- @return: void
- */
- void viewOutBal (userNode *user)
- {
- userNode *temp=NULL;
- temp=user;
- printf("\nViewAccounts With Outstanding Balance: \n");
- do
- {
- if (temp->outstanding <= 0.00)
- printf("Sorry, your outstanding balance is empty!\n");
- else if (temp->outstanding > 0.00)
- {
- printf("Username: %s", temp->username);
- printf("Outstanding Balance is: %.2f\n", temp->outstanding);
- }
- temp=temp->next;
- } while (temp!=NULL);
- }
- /*
- FUNCTION: manageAccounts displays the admin's options for Manage Account Menu
- @param: userNode *user: structure with user information
- @return: void
- */
- void manageAccounts (userNode *user)
- {
- int aChoice;
- do
- {
- printf("\n === 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("5. Return to Administrator Menu\n");
- printf("Enter choice: ");
- scanf("%d", &aChoice);
- switch (aChoice)
- {
- case 1: viewLocked (user);
- break;
- case 2: unlockSpecific (user);
- break;
- case 3: unlockAll (user);
- break;
- case 4: viewOutBal (user);
- break;
- case 5: break;
- }
- } while (aChoice!=5);
- }
- /*
- FUNCTION: uniqueCateg checks if the category is unique or not
- @param: string15 addCateg: string that contains the name of the new category
- @param: categNode *temp: structure with the category information
- @return: int
- */
- int uniqueCateg (string15 addCateg, categNode *temp)
- {
- int unique=1;
- categNode *check=NULL;
- check=temp;
- while(check!=NULL)
- {
- if (strcmp(check->category, addCateg)==0)
- {
- unique=0;
- check=NULL;
- }
- else
- check=check->next;
- }
- return unique;
- }
- /*
- FUNCTION: uniqueProd checks if the product is unique or not
- @param: string15 prod: string that contains the name of the new product
- @param: categNode *temp: structure with the category information
- @return: int
- */
- int uniqueProd (string15 prod, categNode *temp)
- {
- int unique=1;
- categNode *check=NULL;
- check=temp;
- while (check!=NULL)
- {
- if (strcmp(check->productInfo.product, prod)==0)
- {
- unique=0;
- check=NULL;
- }
- else
- check=check->next;
- }
- return unique;
- }
- /*
- FUNCTION: addNewStock allows the admin to add a new stock to the current list of stocks
- and goes back to the Manage Stocks Menu after
- @param: stockNode *stockInfo: structure with stock information
- @param: int *stockctr: to check the number of categories, which but be max of 10
- @param: categNode *stemp: structure with the category information
- @return: categNode *
- */
- void addNewStock(stockNode *stockInfo, int *stockctr, categNode **stemp)
- {
- string15 addCateg, supplier, prod, newcat, newsup, newprod;
- int cChoice=0, accept=0, compare=2, avbl=0, i=0, rNum=0;
- float purchasePrice=0, sellingPrice=0, discountRate=0;
- categNode *stocktemp=NULL;
- stocktemp = malloc(sizeof(categNode));
- srand(time(NULL));
- printf("\nAdding New Stocks: \n");
- do
- {
- printf("Would you like to add a new stock?\n");
- printf("1. Yes\n");
- printf("2. No\n");
- printf("Enter choice: ");
- fflush(stdin);
- scanf("%d", &cChoice);
- if (cChoice!=1 && cChoice!=2)
- printf("Invalid input. Try again\n");
- if ((*stockctr)==0 && cChoice==2)
- printf("\nNo stocks yet!\n\n");
- } while ((cChoice!=1 && (*stockctr)<11)&&(cChoice!=2 && (*stockctr)>0));
- while (cChoice==1 && accept!=1 && (*stockctr)<11)
- {
- do
- {
- printf("Enter Category: ");
- fflush(stdin);
- fgets(addCateg, 16, stdin);
- addCateg[strlen(addCateg)-1]='\0';
- if(strlen(addCateg)>=3 && strlen(addCateg)<=15)
- {
- compare=uniqueCateg(addCateg,*stemp);
- if (compare==1)
- {
- accept=1;
- strcpy (stocktemp->category, addCateg);
- (*stockctr)++;
- printf("You have created a new category! Category #%d\n", *stockctr);
- }else{
- accept=1;
- strcpy (stocktemp->category, addCateg);
- }
- }else
- printf("Enter another category that contains 3-15 characters\n");
- if (*stockctr==10)
- printf("You have reached the maximum amount of categories!\n");
- } while ((strlen(addCateg)<3 && strlen(addCateg)>15) && accept!=1 && (*stockctr)<10);
- }
- accept=0;
- compare=2;
- if (cChoice==1 && accept!=1)
- {
- do
- {
- printf("Enter Supplier: ");
- fflush(stdin);
- fgets(supplier, 16, stdin);
- if (strlen(supplier)<16)
- accept=1;
- else
- printf("Invalid input. Try again!\n");
- } while (accept!=1);
- if (accept==1)
- {
- strcpy(stocktemp->productInfo.supplier, supplier);
- stocktemp->productInfo.supplier[strlen(stocktemp->productInfo.supplier)-1]='\0';
- accept=0;
- }
- do
- {
- printf("Enter Product: ");
- fflush(stdin);
- fgets(prod, 16, stdin);
- prod[strlen(prod)-1]='\0';
- compare=uniqueProd(prod, *stemp);
- if (strlen(prod)<16 && compare==1)
- accept=1;
- else
- printf("Invalid input. Try again!\n");
- } while (accept!=1 && compare!=1);
- if (accept==1)
- {
- strcpy(stocktemp->productInfo.product, prod);
- accept=0;
- }
- do
- {
- printf("Enter Quantity Available: ");
- fflush(stdin);
- scanf("%d", &avbl);
- if (avbl>=0)
- accept=1;
- else
- printf("Invalid input. Try again!\n");
- } while (accept!=1);
- if (accept==1)
- {
- stocktemp->productInfo.avbl=avbl;
- accept=0;
- }
- do
- {
- printf("Enter Purchase Price: ");
- fflush(stdin);
- scanf("%f", &purchasePrice);
- if (purchasePrice>0)
- accept=1;
- else
- printf("Invalid input. Try again!\n");
- } while (accept!=1);
- if (accept==1)
- {
- stocktemp->productInfo.purchasePrice=purchasePrice;
- accept=0;
- }
- do
- {
- printf("Enter Unit Selling Price: ");
- fflush(stdin);
- scanf("%f", &sellingPrice);
- if (sellingPrice>0)
- accept=1;
- else
- printf("Invalid input. Try again!\n");
- } while (accept!=1);
- if (accept==1)
- {
- stocktemp->productInfo.sellingPrice=sellingPrice;
- accept=0;
- }
- do
- {
- printf("Enter Discount Rate: ");
- fflush(stdin);
- scanf("%f", &discountRate);
- if (discountRate>=0)
- accept=1;
- else
- printf("Invalid input. Try again!\n");
- } while (accept!=1);
- if (accept==1)
- {
- stocktemp->productInfo.discountRate=discountRate;
- accept=0;
- }
- }
- strcpy(newcat, addCateg);
- for(i=0; i<strlen(newcat); i++)
- {
- if (newcat[i]>='a' && newcat[i]<='z')
- newcat[i]-=32;
- }
- strcpy(newsup, supplier);
- for(i=0; i<strlen(newsup); i++)
- {
- if (newsup[i]>='a' && newsup[i]<='z')
- newsup[i]-=32;
- }
- strcpy(newprod, prod);
- for(i=0; i<strlen(newprod); i++)
- {
- if (newprod[i]>='a' && newprod[i]<='z')
- newprod[i]-=32;
- }
- stocktemp->productInfo.sold=0;
- stocktemp->productInfo.pCode[0]=newcat[0];
- stocktemp->productInfo.pCode[1]=newsup[0];
- stocktemp->productInfo.pCode[2]=newprod[0];
- i=0;
- while (i<5)
- {
- rNum=rand()%58;
- if(rNum>47 && rNum<57)
- {
- stocktemp->productInfo.pCode[(i+3)]=rNum;
- i++;
- }
- stocktemp->productInfo.pCode[8]='\0';
- }
- if(cChoice!=2){
- printf("Product code: %s\n", stocktemp->productInfo.pCode);
- stocktemp->next = *stemp;
- *stemp = stocktemp;
- }
- }
- /*
- FUNCTION: viewAllStocks: allows the admin to view all the created stocks in a table
- @param: stockNode *stockInfo: structure with stock information
- @param: int *stockctr: to check the number of categories, which must be max of 10
- @param: categNode *stemp: structure with the category information
- @return: void
- */
- void viewAllStocks (stockNode *stockInfo, int *stockctr, categNode *stemp)
- {
- int i;
- int ctr=0;
- printf("\n");
- printf("| CATEGORY | SUPPLIER | PROD |PRODUCT |QTY |QTY |BUY |SELL |DISC|\n");
- printf("| | | CODE | |AVBL|SOLD|PRICE|PRICE|RATE|\n");
- while (stemp!=NULL)
- {
- if(ctr!=20)
- {
- printf("\n");
- printf("%s", stemp->category);
- if(strlen(stemp->category)<15)
- for(i=strlen(stemp->category);i<15;i++)
- printf(" ");
- printf("|%s", stemp->productInfo.supplier);
- if(strlen(stemp->productInfo.supplier)<15)
- for(i=strlen(stemp->productInfo.supplier);i<15;i++)
- printf(" ");
- printf("|%s", stemp->productInfo.pCode);
- printf("|%s", stemp->productInfo.product);
- if(strlen(stemp->productInfo.product)<10)
- for(i=strlen(stemp->productInfo.product);i<10;i++)
- printf(" ");
- printf("|%d", stemp->productInfo.avbl);
- if(stemp->productInfo.avbl<10)
- for(i=0;i<3;i++)
- printf(" ");
- else if(stemp->productInfo.avbl<100)
- for(i=0;i<2;i++)
- printf(" ");
- else if(stemp->productInfo.avbl<1000)
- for(i=0;i<1;i++)
- printf(" ");
- printf("|%d", stemp->productInfo.sold);
- if(stemp->productInfo.sold<10)
- for(i=0;i<3;i++)
- printf(" ");
- else if(stemp->productInfo.sold<100)
- for(i=0;i<2;i++)
- printf(" ");
- else if(stemp->productInfo.sold<1000)
- for(i=0;i<1;i++)
- printf(" ");
- printf("|%.2f", stemp->productInfo.purchasePrice);
- printf("|%.2f", stemp->productInfo.sellingPrice);
- printf("|%.1f", stemp->productInfo.discountRate);
- printf("\n");
- ctr++;
- }
- else
- {
- printf("\nPress Enter to continue...\n");
- fflush(stdin);
- while(getchar() != '\n');
- ctr = 0;
- }
- stemp = stemp->next;
- }
- printf("\nPress Enter to continue...\n");
- fflush(stdin);
- while(getchar() != '\n');
- }
- /*
- FUNCTION: viewStocksCategory: allows the admin to search for stocks based on the category input
- @param: stockNode *stockInfo: structure with stock information
- @param: int *stockctr: to check the number of categories, which must be max of 10
- @param: categNode *stemp: structure with the category information
- @return: void
- */
- void viewStockCategory (stockNode *stockInfo, int *stockctr, categNode *stemp)
- {
- int i,found=0;
- categNode *temp;
- string15 categ;
- int ctr=0;
- printf("Enter category: ");
- fflush(stdin);
- fgets(categ, 16, stdin);
- for(temp=stemp; temp!=NULL&&!found; temp=temp->next)
- {
- if(strcmp(temp->category,categ)==0)
- found = 1;
- }
- if(found)
- {
- printf("\n");
- printf("| CATEGORY | SUPPLIER | PROD |PRODUCT |QTY |QTY |BUY |SELL |DISC|\n");
- printf("| | | CODE | |AVBL|SOLD|PRICE|PRICE|RATE|\n");
- while(stemp!=NULL)
- {
- if(ctr!=20)
- {
- if(strcmp(stemp->category,categ)==0)
- {
- printf("\n");
- printf("%s", stemp->category);
- if(strlen(stemp->category)<15)
- for(i=strlen(stemp->category);i<15;i++)
- printf(" ");
- printf("|%s", stemp->productInfo.supplier);
- if(strlen(stemp->productInfo.supplier)<15)
- for(i=strlen(stemp->productInfo.supplier);i<15;i++)
- printf(" ");
- printf("|%s", stemp->productInfo.pCode);
- printf("|%s", stemp->productInfo.product);
- if(strlen(stemp->productInfo.product)<10)
- for(i=strlen(stemp->productInfo.product);i<10;i++)
- printf(" ");
- printf("|%d", stemp->productInfo.avbl);
- if(stemp->productInfo.avbl<10)
- for(i=0;i<3;i++)
- printf(" ");
- else if(stemp->productInfo.avbl<100)
- for(i=0;i<2;i++)
- printf(" ");
- else if(stemp->productInfo.avbl<1000)
- for(i=0;i<1;i++)
- printf(" ");
- printf("|%d", stemp->productInfo.sold);
- if(stemp->productInfo.sold<10)
- for(i=0;i<3;i++)
- printf(" ");
- else if(stemp->productInfo.sold<100)
- for(i=0;i<2;i++)
- printf(" ");
- else if(stemp->productInfo.sold<1000)
- for(i=0;i<1;i++)
- printf(" ");
- printf("|%.2f", stemp->productInfo.purchasePrice);
- printf("|%.2f", stemp->productInfo.sellingPrice);
- printf("|%.1f", stemp->productInfo.discountRate);
- printf("\n");
- ctr++;
- }
- }
- else
- {
- printf("\nPress Enter to continue...\n");
- fflush(stdin);
- while(getchar() != '\n');
- ctr = 0;
- }
- stemp = stemp->next;
- }
- printf("\nPress Enter to continue...\n");
- fflush(stdin);
- while(getchar() != '\n');
- }
- else
- {
- printf("\nCategory not found.\n");
- printf("\nPress Enter to continue...\n");
- fflush(stdin);
- while(getchar() != '\n');
- }
- }
- /*
- FUNCTION: modStockInfo: allows the admin to modify the stock information
- @param: stockNode *stockInfo: structure with stock information
- @param: int *stockctr: to check the number of categories, which must be max of 10
- @param: categNode *stemp: structure with the category information
- @return: void
- */
- void modStockInfo (stockNode *stockInfo, int *stockctr, categNode *stemp)
- {
- int mChoice=0, rNum, found=0, i=0;
- string8 pCode;
- string15 categ, supp, prod, newcat, newsup, newprod;
- float pPrice=0, sPrice=0, discount=0;
- viewAllStocks (stockInfo, stockctr, stemp);
- printf("Enter Product Code: ");
- scanf("%s",pCode);
- while (stemp!=NULL && found!=1)
- {
- if (strcmp(stemp->productInfo.pCode, pCode)==0)
- found=1;
- else
- stemp=stemp->next;
- }
- if (found!=1)
- printf("Product Code not found!\n");
- if (found==1)
- {
- do
- {
- printf("\nWhat would you like to modify?\n");
- printf("1. Category\n");
- printf("2. Supplier\n");
- printf("3. Product\n");
- printf("4. Purchase Price\n");
- printf("5. Selling Price\n");
- printf("6. Discount\n");
- printf("7. Finish Modification of Product\n");
- printf("Enter choice: ");
- scanf("%d", &mChoice);
- switch (mChoice)
- {
- case 1: do
- {
- printf("Enter New Category: ");
- fflush(stdin);
- fgets(categ, 16, stdin);
- if (strlen(categ)>=3 && strlen(categ)<=15)
- {
- strcpy(stemp->category, categ);
- stemp->category[strlen(stemp->category)-1]='\0';
- }
- else
- printf("\nInvalid input. Try again!\n");
- } while (strlen(stemp->category)<3 && strlen(stemp->category)>15);
- break;
- case 2: do
- {
- printf("Enter New Supplier: ");
- fflush(stdin);
- fgets(supp, 16, stdin);
- if (strlen(supp)>=3 && strlen(supp)<=15)
- {
- strcpy(stemp->productInfo.supplier, supp);
- stemp->productInfo.supplier[strlen(stemp->productInfo.supplier)-1]='\0';
- }
- else
- printf("\nInvalid input. Try again!\n");
- } while (strlen(stemp->productInfo.supplier)<3 && strlen(stemp->productInfo.supplier)>15);
- break;
- case 3: do
- {
- printf("Enter New Product: ");
- fflush(stdin);
- fgets(prod, 16, stdin);
- if (strlen(prod)>=3 && strlen(prod)<=15)
- {
- strcpy(stemp->productInfo.product, prod);
- stemp->productInfo.product[strlen(stemp->productInfo.product)-1]='\0';
- }
- else
- printf("\nInvalid input. Try again!\n");
- } while (strlen(stemp->productInfo.product)<3 && strlen(stemp->productInfo.product)>15);
- break;
- case 4: printf("Enter New Purchase Price: ");
- scanf("%f", &pPrice);
- stemp->productInfo.purchasePrice=pPrice;
- break;
- case 5: printf("Enter Selling Price: ");
- scanf("%f", &sPrice);
- stemp->productInfo.sellingPrice=sPrice;
- break;
- case 6: printf("Enter New Discount Rate: ");
- scanf("%f", &discount);
- stemp->productInfo.discountRate=discount;
- break;
- case 7: strcpy(pCode, stemp->productInfo.pCode);
- strcpy(newcat, categ);
- for(i=0; i<strlen(newcat); i++)
- {
- if (newcat[i]>='a' && newcat[i]<='z')
- newcat[i]-=32;
- }
- strcpy(newsup, supp);
- for(i=0; i<strlen(newsup); i++)
- {
- if (newsup[i]>='a' && newsup[i]<='z')
- newsup[i]-=32;
- }
- strcpy(newprod, prod);
- for(i=0; i<strlen(newprod); i++)
- {
- if (newprod[i]>='a' && newprod[i]<='z')
- newprod[i]-=32;
- }
- if (stemp->productInfo.pCode[0]!=stemp->category[0])
- pCode[0]=newcat[0];
- if (stemp->productInfo.pCode[1]!=stemp->productInfo.supplier[0])
- pCode[1]=newsup[0];
- if (stemp->productInfo.pCode[2]!=stemp->productInfo.product[0])
- pCode[2]=newprod[0];
- i=0;
- while (i<5)
- {
- rNum=rand()%58;
- if(rNum>47 && rNum<57)
- {
- pCode[(i+3)]=rNum;
- i++;
- }
- pCode[8]='\0';
- }
- strcpy(stemp->productInfo.pCode, pCode);
- printf("New Product Code: %s", stemp->productInfo.pCode);
- break;
- }
- } while (mChoice!=7);
- }
- }
- /*
- FUNCTION: restock asks the user which product's number of available items
- they want to modify
- @param: stockNode *stockInfo: structure with stock information
- @param: int *stockctr: to check the number of categories, which must be max of 10
- @param: categNode *stemp: structure with the category information
- @return: void
- */
- void restock (stockNode *stockInfo, int *stockctr, categNode *stemp)
- {
- string8 pCode;
- int found=0, amt=0;
- viewAllStocks (stockInfo, stockctr, stemp);
- printf("\nRestocking:\n");
- printf("Enter Product Code: ");
- fflush(stdin);
- fgets(pCode, 9, stdin);
- while (stemp!=NULL && found==0)
- {
- if (strcmp(stemp->productInfo.pCode, pCode)==0)
- found=1;
- else
- stemp=stemp->next;
- }
- if (found==1)
- {
- printf("Enter modified amount: ");
- scanf("%d", &amt);
- stemp->productInfo.avbl=stemp->productInfo.avbl+amt;
- }
- if (found!=1)
- printf("Last input product code not found: not restocked!\n");
- }
- /*
- FUNCTION: manageStocks asks the admin what they want to do with all the stock information
- @param: stockNode *stockInfo: structure with stock information
- @param: int *stockctr: to check the number of categories, which but be max of 10
- @param: categNode *stemp: structure with the category information
- @return: void
- */
- void manageStocks (stockNode *stockInfo, int *stockctr,categNode **stemp)
- {
- int aChoice=0;
- do
- {
- printf("\n === 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. Save Inventory\n");
- printf("8. Update Inventory from File\n");
- printf("9. Return to Administrator Menu\n");
- printf("Enter choice: ");
- fflush(stdin);
- scanf("%d", &aChoice);
- switch (aChoice)
- {
- case 1: addNewStock (stockInfo, stockctr, stemp);
- break;
- case 2: viewAllStocks (stockInfo, stockctr, *stemp);
- break;
- case 3: viewStockCategory (stockInfo, stockctr, *stemp);
- break;
- case 4: break;
- case 5: modStockInfo (stockInfo, stockctr, stemp);
- break;
- case 6: restock (stockInfo, stockctr, stemp);
- break;
- case 7: break;
- case 8: break;
- case 9: break;
- }
- } while (aChoice>0 && aChoice<9 && aChoice!= 9);
- }
- /*
- FUNCTION: adminMenu displays only when an administrator is able to log in successfully
- It then asks the admin what (s)he wants to do
- @param: userNode *user: structure with the user information
- @param: int *close: option to exit
- @param: stockNode *stockInfo: structure with stock information
- @param: int *stockctr: to check the number of categories, which but be max of 10
- @param: categNode *stemp: structure with the category information
- @return: void
- */
- void adminMenu (userNode *user, int *close, stockNode *stockInfo, int *stockctr, categNode **stemp)
- {
- int adChoice=0;
- do
- {
- printf("\n === ADMINISTRATOR MENU === \n");
- printf("1. Manage Accounts Menu\n");
- printf("2. Manage Stocks Menu\n");
- printf("3. Prepare Delivery Receipt (PHASE 2)\n");
- printf("4. Shutdown Kiosk \n");
- printf("5. Log Out \n");
- printf("Enter choice: ");
- scanf("%d", &adChoice);
- switch (adChoice)
- {
- case 1: manageAccounts(user);
- break;
- case 2: manageStocks(stockInfo, stockctr,stemp);
- break;
- case 3: break;
- case 4: *close=1;
- break;
- case 5: break;
- default: printf("Invalid input. Try again.\n");
- }
- } while (adChoice!=4 && adChoice!=5);
- }
- /*
- FUNCTION: modUserInfo allows the shopper to change his/her account details
- @param: userNode *user: structure about user information
- @return: void
- */
- void modUserInfo (userNode *user)
- {
- int uChoice=0, accept=0, i=0, nameChoice=0;
- string15 newpass;
- printf("\nModifying User Info:\n");
- do
- {
- printf("\nDo you want to...\n");
- printf("1. Change Name\n");
- printf("2. Change Address\n");
- printf("3. Change Password\n");
- printf("4. Return to Shopper Menu\n");
- printf("Enter choice: ");
- scanf("%d", &uChoice);
- switch (uChoice)
- {
- case 1: do
- {
- printf("\nWhat would you like to change? \n");
- printf("1. First Name\n");
- printf("2. Middle Name\n");
- printf("3. Last Name\n");
- printf("4. All Names\n");
- printf("Enter choice: ");
- scanf("%d", &nameChoice);
- } while (nameChoice<1 && nameChoice>4);
- switch (nameChoice)
- {
- case 1: printf("Enter New Name: \n");
- printf("First name: ");
- fflush(stdin);
- fgets(user->info.name.first, 21, stdin);
- break;
- case 2: printf("Enter New Name: \n");
- printf("Middle name: ");
- fflush(stdin);
- fgets(user->info.name.middle, 21, stdin);
- break;
- case 3: printf("Enter New Name: \n");
- printf("Last name: ");
- fflush(stdin);
- fgets(user->info.name.last, 21, stdin);
- break;
- case 4: printf("Enter New Name: \n");
- printf("First name: ");
- fflush(stdin);
- fgets(user->info.name.first, 21, stdin);
- printf("Middle name: ");
- fflush(stdin);
- fgets(user->info.name.middle, 21, stdin);
- printf("Last name: ");
- fflush(stdin);
- fgets(user->info.name.last, 21, stdin);
- break;
- }
- break;
- case 2: printf("Enter New Address: \n");
- printf("Address: ");
- fflush(stdin);
- fgets (user->info.address, 51, stdin);
- break;
- case 3: do
- {
- printf("Enter New Password: ");
- scanf("%s", newpass);
- for (i=0; i<strlen(newpass); i++)
- {
- if (!((newpass[i] >= 'A' && newpass[i] <= 'Z') || (newpass[i] >= 'a' && newpass[i] <= 'z')))
- {
- accept=1;
- strcpy (user->password, newpass);
- }
- }
- } while (strlen(newpass) < 6 || strlen(newpass) > 15 || accept!=1);
- break;
- case 4: break;
- default: printf("Invalid input. Try again.\n");
- }
- } while (uChoice!=4);
- }
- /*
- FUNCTION: browseAllProd: allows the shopper to see all the available products
- @param categNode *stemp: structure with all the category information
- @return: void
- */
- void browseAllProd (categNode *stemp)
- {
- int i,found=0;
- categNode *temp;
- int ctr=0;
- for(temp=stemp; temp!=NULL&&!found; temp=temp->next)
- {
- if(temp->productInfo.avbl>0)
- found = 1;
- }
- if(found)
- {
- printf("\n");
- printf("| CATEGORY | SUPPLIER | PROD |PRODUCT |QTY |QTY |BUY |SELL |DISC|\n");
- printf("| | | CODE | |AVBL|SOLD|PRICE|PRICE|RATE|\n");
- while(stemp!=NULL)
- {
- if(ctr!=20)
- {
- if(stemp->productInfo.avbl>0)
- {
- printf("\n");
- printf("%s", stemp->category);
- if(strlen(stemp->category)<15)
- for(i=strlen(stemp->category);i<15;i++)
- printf(" ");
- printf("|%s", stemp->productInfo.supplier);
- if(strlen(stemp->productInfo.supplier)<15)
- for(i=strlen(stemp->productInfo.supplier);i<15;i++)
- printf(" ");
- printf("|%s", stemp->productInfo.pCode);
- printf("|%s", stemp->productInfo.product);
- if(strlen(stemp->productInfo.product)<10)
- for(i=strlen(stemp->productInfo.product);i<10;i++)
- printf(" ");
- printf("|%d", stemp->productInfo.avbl);
- if(stemp->productInfo.avbl<10)
- for(i=0;i<3;i++)
- printf(" ");
- else if(stemp->productInfo.avbl<100)
- for(i=0;i<2;i++)
- printf(" ");
- else if(stemp->productInfo.avbl<1000)
- for(i=0;i<1;i++)
- printf(" ");
- printf("|%d", stemp->productInfo.sold);
- if(stemp->productInfo.sold<10)
- for(i=0;i<3;i++)
- printf(" ");
- else if(stemp->productInfo.sold<100)
- for(i=0;i<2;i++)
- printf(" ");
- else if(stemp->productInfo.sold<1000)
- for(i=0;i<1;i++)
- printf(" ");
- printf("|%.2f", stemp->productInfo.purchasePrice);
- printf("|%.2f", stemp->productInfo.sellingPrice);
- printf("|%.1f", stemp->productInfo.discountRate);
- printf("\n");
- ctr++;
- }
- }
- else
- {
- printf("\nPress Enter to continue...\n");
- fflush(stdin);
- while(getchar() != '\n');
- ctr = 0;
- }
- stemp = stemp->next;
- }
- printf("\nPress Enter to continue...\n");
- fflush(stdin);
- while(getchar() != '\n');
- }
- else
- {
- printf("\nNo available products.\n");
- printf("\nPress Enter to continue...\n");
- fflush(stdin);
- while(getchar() != '\n');
- }
- }
- /*
- FUNCTION: browseAllCateg: allows the shopper to search for a specific category and
- display the following products
- @param categNode *stemp: structure with all the category information
- @return: void
- */
- void browseAllCateg (categNode *stemp)
- {
- int i,found=0;
- categNode *temp;
- int ctr=0;
- string15 categ;
- printf("Enter category: ");
- fflush(stdin);
- scanf("%s",categ);
- for(temp=stemp; temp!=NULL&&!found; temp=temp->next)
- {
- if(strcmp(temp->category,categ)==0)
- found = 1;
- }
- if(found)
- {
- printf("\n");
- printf("| CATEGORY | SUPPLIER | PROD |PRODUCT |QTY |QTY |BUY |SELL |DISC|\n");
- printf("| | | CODE | |AVBL|SOLD|PRICE|PRICE|RATE|\n");
- while(stemp!=NULL)
- {
- if(ctr!=20)
- {
- if(strcmp(stemp->category,categ)==0)
- if(temp->productInfo.avbl>0)
- {
- printf("\n");
- printf("%s", stemp->category);
- if(strlen(stemp->category)<15)
- for(i=strlen(stemp->category); i<15; i++)
- printf(" ");
- printf("|%s", stemp->productInfo.supplier);
- if(strlen(stemp->productInfo.supplier)<15)
- for(i=strlen(stemp->productInfo.supplier); i<15; i++)
- printf(" ");
- printf("|%s", stemp->productInfo.pCode);
- printf("|%s", stemp->productInfo.product);
- if(strlen(stemp->productInfo.product)<10)
- for(i=strlen(stemp->productInfo.product); i<10; i++)
- printf(" ");
- printf("|%d", stemp->productInfo.avbl);
- if(stemp->productInfo.avbl<10)
- for(i=0; i<3; i++)
- printf(" ");
- else if(stemp->productInfo.avbl<100)
- for(i=0; i<2; i++)
- printf(" ");
- else if(stemp->productInfo.avbl<1000)
- for(i=0; i<1; i++)
- printf(" ");
- printf("|%d", stemp->productInfo.sold);
- if(stemp->productInfo.sold<10)
- for(i=0; i<3; i++)
- printf(" ");
- else if(stemp->productInfo.sold<100)
- for(i=0; i<2; i++)
- printf(" ");
- else if(stemp->productInfo.sold<1000)
- for(i=0; i<1; i++)
- printf(" ");
- printf("|%.2f", stemp->productInfo.purchasePrice);
- printf("|%.2f", stemp->productInfo.sellingPrice);
- printf("|%.1f", stemp->productInfo.discountRate);
- printf("\n");
- ctr++;
- }
- }
- else
- {
- printf("\nPress Enter to continue...\n");
- fflush(stdin);
- while(getchar() != '\n');
- ctr=0;
- }
- stemp=stemp->next;
- }
- printf("\nPress Enter to continue...\n");
- fflush(stdin);
- while(getchar() != '\n');
- }
- else
- {
- printf("\nNo available products.\n");
- printf("\nPress Enter to continue...\n");
- fflush(stdin);
- while(getchar() != '\n');
- }
- }
- /*
- FUNCTION: browseAllSale: allows the shopper to see all the available products with discount
- @param categNode *stemp: structure with all the category information
- @return: void
- */
- void browseAllSale (categNode *stemp)
- {
- int i,found=0;
- categNode *temp;
- int ctr=0;
- for(temp=stemp; temp!=NULL&&!found; temp=temp->next)
- {
- if(temp->productInfo.discountRate>0)
- found = 1;
- }
- if(found)
- {
- printf("\n");
- printf("| CATEGORY | SUPPLIER | PROD |PRODUCT |QTY |QTY |BUY |SELL |DISC|\n");
- printf("| | | CODE | |AVBL|SOLD|PRICE|PRICE|RATE|\n");
- while(stemp!=NULL)
- {
- if(ctr!=20)
- {
- if(stemp->productInfo.discountRate>0)
- {
- printf("\n");
- printf("%s", stemp->category);
- if(strlen(stemp->category)<15)
- for(i=strlen(stemp->category);i<15;i++)
- printf(" ");
- printf("|%s", stemp->productInfo.supplier);
- if(strlen(stemp->productInfo.supplier)<15)
- for(i=strlen(stemp->productInfo.supplier);i<15;i++)
- printf(" ");
- printf("|%s", stemp->productInfo.pCode);
- printf("|%s", stemp->productInfo.product);
- if(strlen(stemp->productInfo.product)<10)
- for(i=strlen(stemp->productInfo.product);i<10;i++)
- printf(" ");
- printf("|%d", stemp->productInfo.avbl);
- if(stemp->productInfo.avbl<10)
- for(i=0; i<3; i++)
- printf(" ");
- else if(stemp->productInfo.avbl<100)
- for(i=0; i<2; i++)
- printf(" ");
- else if(stemp->productInfo.avbl<1000)
- for(i=0; i<1; i++)
- printf(" ");
- printf("|%d", stemp->productInfo.sold);
- if(stemp->productInfo.sold<10)
- for(i=0; i<3; i++)
- printf(" ");
- else if(stemp->productInfo.sold<100)
- for(i=0; i<2; i++)
- printf(" ");
- else if(stemp->productInfo.sold<1000)
- for(i=0; i<1; i++)
- printf(" ");
- printf("|%.2f", stemp->productInfo.purchasePrice);
- printf("|%.2f", stemp->productInfo.sellingPrice);
- printf("|%.1f", stemp->productInfo.discountRate);
- printf("\n");
- ctr++;
- }
- }
- else
- {
- printf("\nPress Enter to continue...\n");
- fflush(stdin);
- while(getchar() != '\n');
- ctr = 0;
- }
- stemp = stemp->next;
- }
- printf("\nPress Enter to continue...\n");
- fflush(stdin);
- while(getchar() != '\n');
- }
- else
- {
- printf("\nNo available products.\n");
- printf("\nPress Enter to continue...\n");
- fflush(stdin);
- while(getchar() != '\n');
- }
- }
- /*
- FUNCTION: settleOut: settles the user's outstanding balance
- @param: userNode *user: structure that contains the user information
- @return: void
- */
- void settleOut (userNode *user)
- {
- userNode *temp=NULL;
- temp=user;
- if (temp!=NULL)
- {
- printf("Your Outstanding Balance: %.2f", user->outstanding);
- printf("\nEnter Credit Card Information: \n");
- }
- }
- /*
- FUNCTION: shopperMenu displays when a shopper logs in successfully
- It then asks the shopper what he/she wants to do
- @param: userNode *user: structure with the user information
- @param: stockNode *stockInfo: structure with stock information
- @param: int *stockctr: to check the number of categories, which but be max of 10
- @return: void
- */
- void shopperMenu (userNode *user, stockNode *stockInfo, int *stockchtr,categNode **stemp)
- {
- int sChoice=0;
- do
- {
- printf("\n === 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");
- printf("5. Add to Cart\n");
- printf("6. View Cart\n");
- printf("7. Settle Outstanding Balance\n");
- printf("8. Log Out\n");
- printf("Enter choice: ");
- scanf("%d", &sChoice);
- switch (sChoice)
- {
- case 1: modUserInfo (user);
- break;
- case 2: browseAllProd (*stemp);
- break;
- case 3: browseAllCateg (*stemp);
- break;
- case 4: browseAllSale (*stemp);
- break;
- case 5: break;
- case 6: break;
- case 7: if (user->outstanding>0)
- settleOut(user);
- else
- break;
- break;
- case 8: break;
- }
- } while (sChoice!=8);
- }
- /*
- FUNCTION: login allows the user to log in to a specific account
- @param: userNode *user: structure with the user information
- categNode **stemp: structure with the stock information
- @return: void
- */
- void login (userNode *user,categNode **stemp)
- {
- int compare=2, found=0, close=0, stockctr=0, attempt=0;
- char cDump;
- string15 uname, pword;
- userNode *temp=NULL;
- stockNode *stockInfo=NULL;
- temp=user;
- printf(" === LOGIN === \n");
- printf("Enter username: ");
- scanf("%s%c", uname, &cDump);
- while (found==0 && temp!=NULL)
- {
- compare=strcmp(uname, temp->username);
- if (compare==0)
- found=1;
- else
- temp=temp->next;
- }
- if (found==1 && temp->isLocked==0)
- {
- do
- {
- printf("Enter password: ");
- scanf("%s%c", pword, &cDump);
- compare=strcmp(pword, temp->password);
- if (compare==0)
- {
- switch (temp->type)
- {
- case 1: printf("\nWelcome back, Admin!\n");
- close=1;
- adminMenu (user, &close, stockInfo, &stockctr, stemp);
- break;
- case 2: printf("\nWelcome back, Shopper!\n");
- close=1;
- shopperMenu(user, stockInfo, &stockctr, stemp);
- break;
- }
- }
- else
- {
- attempt++;
- printf("Incorrect password. Try again.\n");
- printf("%d out of 3 tries\n", attempt);
- if (attempt==3)
- {
- user->isLocked=1;
- printf("\nYou have tried logging in too many times.\n");
- printf("Please contact the administrator.\n");
- }
- }
- } while (!close && attempt<=3 && temp->isLocked==0);
- }
- else
- printf("\nSorry, username does not exist.\n");
- }
- /*
- FUNCTION: getUserInfo asks the user for their name (first, middle, last) information
- as well as their address
- @param: userInfoType *pInfo: structure of the data of the current user with contains user information
- @return: void
- */
- void getUserInfo (userInfoType *pInfo)
- {
- getchar();
- printf("Enter name: \n");
- printf("First name: ");
- fgets(pInfo->name.first, 21, stdin);
- printf("Middle name: ");
- fgets(pInfo->name.middle, 21, stdin);
- printf("Last name: ");
- fgets(pInfo->name.last, 21, stdin);
- 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';
- printf("%s, %s %s \n", pInfo->name.last, pInfo->name.first, pInfo->name.middle);
- }
- /*
- FUNCTION: checkUnique is to verify if the username is unique or not
- @param: string15 uname: chosen username of new user
- @param: userNode *user: structure with the user information
- @return: int: 0 if not unique, 1 if unique
- */
- int checkUnique (string15 uname, userNode *user)
- {
- int unique=1;
- userNode *temp=NULL;
- temp=user;
- while(temp!=NULL)
- {
- if (strcmp(temp->username, uname)==0)
- {
- unique=0;
- temp=NULL;
- }
- else
- temp=temp->next;
- }
- return unique;
- }
- /*
- FUNCTION: signUp allows the user to create more accounts and adding it to the current
- list of users
- @param: userNode *user: structure which contains infomation of all users
- @param: userNode *pNew: structure which contains information of the current user
- @return: void
- */
- void signUp (userNode *user, userNode *pNew)
- {
- int chk=0, i=0, compare=2, accept=0, choice=0, close=1, change=0;
- char cDump;
- /* for authorization code */
- string8 ac;
- string15 uname, pword;
- if (user==NULL)
- {
- /* first account to sign up */
- do
- {
- printf("=== SIGN UP ===\n");
- printf("Enter username: ");
- scanf("%s%c", uname, &cDump);
- } while ((strlen(uname) < 3 || strlen(uname) > 15));
- strcpy (pNew->username, uname);
- }
- else
- {
- /* second account and onwards to sign up */
- do
- {
- printf("=== SIGN UP ===\n");
- printf("Enter username: ");
- scanf("%s%c", uname, &cDump);
- if (strlen(uname) >=3 && strlen(uname)<=15)
- {
- compare=checkUnique(uname, user);
- if (compare==1)
- {
- accept=1;
- strcpy (pNew->username, uname);
- }
- else if (compare!=1)
- {
- accept=0;
- printf("Username unavailable. Try again.\n");
- }
- }
- } while (strlen(uname) < 3 || strlen(uname) > 15 || accept==0 || compare!=1);
- }
- printf("Username is: %s\n", pNew->username);
- accept=0;
- do
- {
- printf("Enter password: ");
- scanf("%s", pword);
- if (strlen(pword) >= 6 || strlen(pword) <= 15)
- {
- for (i=0; i<strlen(pword); i++)
- {
- if (!((pword[i] >= 'A' && pword[i] <= 'Z') || (pword[i] >= 'a' && pword[i] <= 'z')))
- {
- accept=1;
- chk=1;
- strcpy (pNew->password, pword);
- }
- }
- if (accept!=1)
- printf("Invalid password. Input at least 1 non-letter.\n");
- }
- else
- accept=0;
- } while (chk==0 || accept!=1 || strlen(pword) < 6 || strlen(pword) > 15);
- printf("Password is: %s\n", pNew->password);
- getUserInfo(&pNew->info); /* (&pUser->info) */
- /* to ask the user to ask which type of account (s)he prefers to make */
- do
- {
- printf("\nChoose your type of account: \n");
- printf("1. Administrator\n");
- printf("2. Shopper\n");
- printf("Enter choice: ");
- scanf("%d", &choice);
- while (choice!=1 && choice!=2)
- {
- printf("Invalid choice. Try again.\n");
- printf("Choose your type of account: \n");
- printf("1. Administrator\n");
- printf("2. Shopper\n");
- printf("Enter choice: ");
- scanf("%d", &choice);
- }
- pNew->type=choice;
- switch (pNew->type)
- {
- /* if user chooses to be an administrator */
- case 1: do
- {
- printf("Input authorization code: ");
- scanf("%s", ac);
- /* to check if authorization code is valid */
- if (strcmp(ac, "DLSU2017")==0)
- printf("\nHello New Admin!\n");
- else
- {
- printf("\nSorry, invalid authorization code.\n");
- printf("1. Try again\n");
- printf("2. Change account type\n");
- printf("Enter choice: ");
- scanf("%d", &change);
- while (change!=1 && change!=2)
- printf("\nInvalid input!\n");
- switch (change)
- {
- case 1: close=1;
- break;
- case 2: close=0;
- break;
- }
- }
- } while (strcmp(ac, "DLSU2017")!=0 && close!=0);
- break;
- /* if user chooses to be a shopper */
- case 2: printf("\nHello Shopper!\n\n");
- pNew->creditLimit=5000.00;
- pNew->outstanding=0.00;
- pNew->nItems=0;
- pNew->isLocked=0;
- /* to tell the user more information about his/her account */
- printf("Your Credit Limit is: PhP %.2f.\n", pNew->creditLimit);
- printf("Your Outstanding Balance is: PhP %.2f.\n", pNew->outstanding);
- printf("Your Cart currently contains: %d items.\n", pNew->nItems);
- break;
- default: printf("Invalid input!\n");
- }
- } while (close==0 && change==2);
- /* recap for the user */
- printf("\n === REMEMBER ===\n");
- printf("Username is: %s\n", pNew->username);
- printf("Password is: %s\n\n", pNew->password);
- }
- /*
- FUNCTION: displayAllRecur displays all the usernames available
- @param: userNode *user: structure which contains infomation of all users
- @return: void
- */
- void displayAllRecur (userNode *user)
- {
- if (user!=NULL)
- {
- printf("%s \n", user->username);
- user=user->next;
- }
- }
- /*
- FUNCTION: freeAll frees all the data from the user structures
- @param: userNode **user: structure containing the data of the all users
- @return: void
- */
- void freeAll (userNode **user)
- {
- userNode *pDel;
- pDel=NULL;
- while (user!=NULL)
- {
- pDel=*user;
- *user=(*user)->next;
- free(pDel);
- }
- }
- /*
- FUNCTION: freeAllStocks frees all the data from the stock structures
- @param: stockNode **pStocks: structure containing the data of the stocks
- @return: void
- */
- void freeAllStocks (stockNode **pStocks)
- {
- stockNode *pDel;
- pDel=NULL;
- while(pStocks!=NULL)
- {
- pDel=*pStocks;
- *pStocks=(*pStocks)->next;
- free(pDel);
- }
- }
- int main()
- {
- int choice=0, close=0, nChoice=0;
- userNode *user, *pNew, *pLast, *pRun, *pTrail;
- categNode *stemp=NULL;
- stockNode *pStocks;
- user=NULL;
- pNew=NULL;
- pLast=NULL;
- pRun=NULL;
- pTrail=NULL;
- pStocks=NULL;
- printf("\t\t\t\t\t\t========== WELCOME! ==========\n");
- do
- {
- printf("\n=== MAIN MENU ===\n");
- printf("1. Login\n");
- printf("2. Sign-up\n");
- printf("3. Exit\n");
- printf("Enter choice: ");
- scanf("%d", &choice);
- printf("\n");
- while(choice!=1 && choice!=2 && choice!=3)
- {
- fflush(stdin);
- printf("Try Again!\n");
- printf("\n=== MAIN MENU ===\n");
- printf("1. Login\n");
- printf("2. Sign-up\n");
- printf("3. Exit\n");
- printf("Enter choice: ");
- scanf("%d", &choice);
- printf("\n");
- }
- switch (choice)
- {
- case 1: if (user==NULL)
- printf("There are not any users yet! Sign up first.\n");
- else
- {
- printf("You chose to login!\n\n");
- login(user,&stemp);
- }
- break;
- case 2: printf("You chose to sign-up!\n\n");
- do
- {
- pNew=malloc(sizeof(userNode));
- signUp(user, pNew);
- pNew->next=NULL;
- if (user==NULL)
- user=pNew;
- else if (strcmp(user->username, pNew->username)>0)
- {
- pNew->next=user;
- user=pNew;
- }
- else
- {
- pRun=user;
- while (pRun!=NULL && strcmp(pRun->username, pNew->username)<0)
- {
- pTrail=pRun;
- pRun=pRun->next;
- }
- pTrail->next=pNew;
- pNew->next=pRun;
- }
- do
- {
- printf("Would you like to add another user?\n");
- printf("1. Yes\n");
- printf("2. No\n");
- printf("Enter choice: ");
- scanf("%d", &nChoice);
- } while (nChoice!=1 && nChoice!=2);
- } while (nChoice==1);
- break;
- case 3: printf("Closing program...\n");
- close=1;
- break;
- default: printf("Invalid input.\n");
- }
- } while (!close&&choice!=3);
- if (user!=NULL)
- freeAll(&user);
- if (pStocks!=NULL)
- freeAllStocks (&pStocks);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement