Advertisement
Guest User

I am not risking it

a guest
Mar 26th, 2017
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.39 KB | None | 0 0
  1. /**********************************************************************************************************************
  2. This is to certify that this project is my own work, based on my personal efforts in studying and applying the concepts
  3. learned. I have constructed the functions and their respective algorithms and corresponding code by myself. The program
  4. was run, tested, and debugged by my own efforts. I further certify that I have not copied in part or whole or otherwise
  5. plagiarized the work of other students and/or persons.
  6. Kyle Christian Ramon L. Santiago, DLSU ID# 11608722
  7. **********************************************************************************************************************/
  8.  
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #define MAXCHAR 16
  14. #define MAXADD 51
  15. #define MAXNAME 21
  16. #define MAXCODE 9
  17. #define MAXCART 100
  18. #define MAXCAT 10
  19. typedef char Char [MAXCHAR];
  20. typedef char Name [MAXNAME];
  21. typedef char Add [MAXADD];
  22. typedef char Code [MAXCODE];
  23. typedef char Adcd [MAXCODE];
  24. typedef struct {
  25. Name First;
  26. Name Second;
  27. Name Last;
  28. }sName;
  29. typedef struct {
  30. sName Userinfo;
  31. Add Address;
  32. }Userinfo;
  33. typedef struct {
  34. Code Prodcode;
  35. int qty;
  36. }ProductTag;
  37. typedef ProductTag arrBought[MAXCART];
  38. typedef struct Usertag {
  39. Char username;
  40. Char password;
  41. Userinfo info;
  42. char type;
  43. float credlimit;
  44. float outstanding;
  45. arrBought cart;
  46. int nItems;
  47. int count;
  48. int checkout;
  49. struct Usertag *pNext;
  50. struct Usertag *pPrev;
  51. };
  52. typedef struct Usertag Usertype;
  53. typedef Usertype * ptrUser;
  54. typedef struct Productlist{
  55. Char supplier;
  56. Char product;
  57. int quantity;
  58. float purchase;
  59. float unit;
  60. float discount;
  61. int sold;
  62. Code code;
  63. struct Productlist *pNext;
  64. };
  65. typedef struct Productlist Prodlist;
  66. typedef struct {
  67. Char category;
  68. Prodlist *list;
  69. int count;
  70. }Stock;
  71. typedef Stock Stocks[MAXCAT];
  72.  
  73. void getUserinfo (Userinfo *uInfo){ /* Gets user's information */
  74. printf("Enter your First Name: ");
  75. fgets(uInfo->Userinfo.First ,MAXNAME,stdin);
  76. printf("Enter your Middle Name: ");
  77. fgets(uInfo->Userinfo.Second,MAXNAME,stdin);
  78. printf("Enter your Last Name: ");
  79. fgets(uInfo->Userinfo.Last,MAXNAME,stdin);
  80. printf("Enter your Address: ");
  81. fgets(uInfo->Address,MAXADD,stdin);
  82. uInfo->Userinfo.Last[strlen(uInfo->Userinfo.Last)-1]='\0';
  83. uInfo->Userinfo.First[strlen(uInfo->Userinfo.First)-1]='\0';
  84. uInfo->Userinfo.Second[strlen(uInfo->Userinfo.Second)-1]='\0';
  85. if (uInfo->Userinfo.First[0] >= 97 && uInfo->Userinfo.First[0] <=122)
  86. uInfo->Userinfo.First[0]-=32;
  87. if (uInfo->Userinfo.Second[0] >= 97 && uInfo->Userinfo.Second[0] <=122)
  88. uInfo->Userinfo.Second[0]-=32;
  89. if (uInfo->Userinfo.Last[0] >= 97 && uInfo->Userinfo.Last[0] <=122)
  90. uInfo->Userinfo.Last[0]-=32;
  91. printf("Your Name is: ");
  92. printf("%s, %s %s\n",uInfo->Userinfo.Last,uInfo->Userinfo.First,uInfo->Userinfo.Second);
  93. printf("Your Address is: ");
  94. printf("%s\n",uInfo->Address);
  95. }
  96. int passcheck (Usertype *user){ /* Checks if there is a non-letter character */
  97. int i,count=0;
  98. for (i=0;i<strlen(user->password);i++)
  99. if ((user->password[i] < 'A' || user->password[i] > 'Z'))
  100. if ((user->password[i] < 'a' || user->password[i] > 'z'))
  101. count++;
  102. if (count==0)
  103. printf("You must have at least 1 non-letter character\n");
  104. return count;
  105. }
  106. int length (Usertype *user){ /* Checks the length of password */
  107. if (strlen (user->password) < 6){
  108.  
  109. printf("password is too short \n");
  110. return 0;
  111. }
  112.  
  113. else if (strlen (user->password) > 15){
  114. printf("password is too long \n");
  115. return 0;
  116. }
  117. else return 1;
  118. }
  119. int Useravailable (Usertype *user, char input[]) { /* Checks if user name is available */
  120. ptrUser pTemp;
  121. while (user != NULL) {
  122. pTemp = user;
  123. user = user->pNext;
  124. if (strcmp (input,pTemp->username)==0){
  125. printf("Your username is taken. Enter another \n");
  126. return 1;
  127. }
  128. }
  129. return 0;
  130. }
  131. void Signup (Usertype *user, Usertype *list){ /* Signup */
  132. char cDump;
  133. Adcd Admincode;
  134. Char input;
  135.  
  136. do{
  137. printf("Username must be 3-15 characters long\n");
  138. printf("Enter Username: ");
  139. scanf("%s%c",&input,&cDump);
  140. } while (Useravailable (list,input) || (strlen (input) < 3|| strlen(input) > 15));
  141. strcpy(user->username,input);
  142.  
  143. do{
  144. printf("Password must be 6-15 characters long and have 1 non letter character\n");
  145. printf("Enter Password: ");
  146. scanf("%s%c",user->password,&cDump);
  147. } while (length (user)==0 || passcheck(user)==0);
  148.  
  149. getUserinfo (&user->info);
  150. printf("Enter account type [S]hopper or [A]dmin : ");
  151. scanf("%c",&user->type);
  152. if (user->type=='s'|| user->type=='S'){
  153. user->credlimit = 5000.00;
  154. user->outstanding = 0.00;
  155. user->nItems = 0;
  156. user->checkout = 0;
  157. user->type = 'S';
  158. printf("Credit limit: %0.2f \n",user->credlimit);
  159. printf("Outstanding balance: %0.2f \n",user->outstanding);
  160. printf("Your cart is empty \n");
  161. }
  162. else if (user->type == 'a' || user->type == 'A'){
  163. printf("Enter Admin Code: \n");
  164. do{
  165. scanf("%s",Admincode);
  166. if (strcmp(Admincode,"DLSU2017")==0)
  167. user->type = 'A';
  168. else printf("Wrong code,try again \n");
  169. } while (strcmp(Admincode,"DLSU2017")!=0);
  170. }
  171. user->count=0;
  172. }
  173. int login (ptrUser user, ptrUser *pAccount) { /* login */
  174. Char input;
  175. ptrUser pTemp,pFirst=user;
  176. if (user == NULL){
  177. printf("No Users, please sign up\n");
  178. return 0;
  179. }
  180. do {
  181. printf("Enter Username: ");
  182. scanf("%s",&input);
  183. while (user != NULL) {
  184. pTemp = user;
  185. user = user->pNext;
  186. if (strcmp (pTemp->username, input )==0){
  187. printf("USERNAME FOUND: %s \n",pTemp->username);
  188. if (pTemp->count < 3){
  189. do {
  190. printf("Enter Password: ");
  191. scanf("%s",&input);
  192. if (strcmp (pTemp->password, input)!=0){
  193. printf("Try again, %d tries left\n",3-pTemp->count);
  194. pTemp->count++;
  195. }
  196. } while (pTemp->count < 4 && strcmp (pTemp->password,input) != 0);
  197. }
  198. printf("SUCCESFUL %s \n",pTemp->username);
  199. if (strcmp(pTemp->password, input) == 0){
  200. *pAccount = pTemp;
  201. return 1;
  202. }
  203. else if (pTemp->count > 3) {
  204. printf("Your account has been locked, contact an admin \n");
  205. return 0;
  206. }
  207. }
  208. }
  209. printf("USERNAME NOT FOUND \n");
  210. user=pFirst;
  211. } while (strcmp (user->username,input));
  212. return 0;
  213. }
  214. void displayAll (ptrUser pUser){ /* Displays all accounts */
  215. while (pUser != NULL) {
  216. printf("%s\n",pUser->username);
  217. pUser=pUser->pNext;
  218. }
  219. }
  220. void Displaylock (Usertype *user){ /* Displays all locekd accounts */
  221. printf("Locked Accounts \n");
  222. while (user != NULL) {
  223. if (user->count > 3)
  224. printf("%s\n",user->username);
  225. user = user->pNext;
  226. }
  227. }
  228. ptrUser search (ptrUser pFirst, Char username){ /* Searches for specific user */
  229. ptrUser pRun;
  230. pRun = pFirst;
  231. while (pRun != NULL && strcmp(username,pRun->username) != 0)
  232. pRun = pRun->pNext;
  233. return pRun;
  234. }
  235. void Unlockaccount (Usertype *user) { /* Unlocks a specific user */
  236. Char input;
  237. ptrUser pTemp;
  238. printf("Enter Account to Unlock \n");
  239. scanf("%s",&input);
  240. pTemp=search (user,input);
  241. pTemp->count = 0;
  242. printf("Account of %s has been unlocked \n",pTemp->username);
  243. }
  244. void Unlockall (Usertype *user) { /* Unlocks all users */
  245. while (user != NULL) {
  246. if (user->count > 3)
  247. user->count = 0;
  248. user = user->pNext;
  249. }
  250. printf("All Accounts Unlocked \n");
  251. }
  252. void Viewaccounts (Usertype *user) { /* Displays all users with outstanding balance */
  253. while (user != NULL) {
  254. if (user->outstanding)
  255. printf("%s has an outstanding balance of %0.2f \n",user->username,user->outstanding);
  256. user = user->pNext;
  257. }
  258. }
  259. void Manageaccounts (Usertype *user) { /* Manage accounts menu */
  260. int exit=1,input;
  261. do {
  262. printf("Manage Accounts \n");
  263. printf("Choose an option \n");
  264. printf("View Locked Accounts : 1 \n");
  265. printf("Unlock Specific Account : 2 \n");
  266. printf("Unlock All Locked Accounts : 3 \n");
  267. printf("View Accounts With Outstanding Balance : 4 \n");
  268. printf("Return to Admin Menu : 5 \n");
  269. scanf("%d",&input);
  270. switch (input) {
  271. case 1: Displaylock (user); break;
  272. case 2: Unlockaccount (user); break;
  273. case 3: Unlockall (user); break;
  274. case 4: Viewaccounts (user); break;
  275. case 5: exit = 0; break;
  276. }
  277. }while (exit);
  278. }
  279. void Viewallstock (Stocks *stock, int *nCat, int n) { /* Displays all stocks */
  280. int i,count=0;
  281. char cDump;
  282. Prodlist *temp;
  283. printf("Viewing All Stock\n");
  284. if (n==0){
  285. for (i=0;i<(*nCat);i++){
  286. temp = stock[i]->list;
  287. while (temp!=NULL){
  288. if (count == 0)
  289. printf(" Category Supplier Product Code Product Available Sold Purchase Selling Discount\n");
  290. printf("%15s ",stock[i]->category);
  291. printf("%15s ",temp->supplier);
  292. printf("%14s ",temp->code);
  293. printf("%15s ",temp->product);
  294. printf("%9d ",temp->quantity);
  295. printf("%4d ",temp->sold);
  296. printf("%7.2f ",temp->purchase);
  297. printf("%7.2f ",temp->unit);
  298. printf("%7.2f \n",temp->discount);
  299. count++;
  300. if (count > 20) {
  301. printf("NEXT PAGE ");
  302. scanf("%c",&cDump);
  303. scanf("%c",&cDump);
  304. count = 0;
  305. }
  306. temp=temp->pNext;
  307. }
  308. }
  309. }
  310. else {
  311. for (i=0;i<(*nCat);i++){
  312. temp = stock[i]->list;
  313. while (temp!=NULL){
  314. if (count == 0)
  315. printf(" Category Brand Product Code Product Available Sold Unit Discount\n");
  316. printf("%15s ",stock[i]->category);
  317. printf("%15s ",temp->supplier);
  318. printf("%14s ",temp->code);
  319. printf("%15s ",temp->product);
  320. printf("%9d ",temp->quantity);
  321. printf("%4d ",temp->sold);
  322. printf("%7.2f ",temp->unit);
  323. printf("%7.2f \n",temp->discount);
  324. count++;
  325. if (count > 20) {
  326. printf("NEXT PAGE ");
  327. scanf("%c",&cDump);
  328. scanf("%c",&cDump);
  329. count = 0;
  330. }
  331. temp=temp->pNext;
  332. }
  333. }
  334. }
  335. }
  336. int Getcat (Stocks *stock, Char input, int nCat) {
  337. int i;
  338. if (nCat==0)
  339. return 0;
  340. else {
  341. for (i=0;i<nCat;i++)
  342. if (strcmp(input,stock[i]->category)==0)
  343. return i;
  344. return nCat;
  345. }
  346. }
  347. void Alphabeticalindex (Stocks *stock, int nCat) {
  348. int swap, i;
  349. Char sTemp;
  350. Prodlist *pTemp;
  351. do{
  352. swap = 0;
  353. for(i=0; i<(nCat)-1; i++)
  354. if(strcmp(stock[i] -> category, stock[i+1] -> category)>0){
  355. strcpy(sTemp, stock[i] -> category);
  356. strcpy(stock[i] -> category, stock[i+1] -> category);
  357. strcpy(stock[i+1] -> category, sTemp);
  358. pTemp = stock[i] -> list;
  359. stock[i] -> list = stock[i+1] -> list;
  360. stock[i+1] -> list = pTemp;
  361. swap=1;
  362. }
  363. }while(swap);
  364. }
  365. void Getprodinfo (Prodlist *pNew,Stocks *stock,int n){
  366. int i;
  367. printf("Enter Supplier : ");
  368. fgets (pNew->supplier,16,stdin);
  369. printf("Enter Product : ");
  370. fgets (pNew->product,16,stdin);
  371. printf("Enter Quantity Available : ");
  372. scanf("%d",&pNew->quantity);
  373. printf("Enter Purchase Price : ");
  374. scanf("%f",&pNew->purchase);
  375. printf("Enter Unit Selling Price : ");
  376. scanf("%f",&pNew->unit);
  377. printf("Enter Discount Rate : ");
  378. scanf("%f",&pNew->discount);
  379. pNew->sold = 0;
  380. pNew->code[0] = stock[n]->category[0];
  381. pNew->code[1] = pNew->supplier[0];
  382. pNew->code[2] = pNew->product[0];
  383. for (i=3;i<8;i++)
  384. pNew->code[i] = rand() % 10 + '0';
  385. pNew->supplier[strlen(pNew->supplier)-1] ='\0';
  386. pNew->product [strlen(pNew->product)-1] = '\0';
  387. pNew->code[8] = '\0';
  388. }
  389. void Addstock (Stocks *stock,int *nCat) { /* Adds Stock */
  390. int i,valid=1,n=-1;
  391. Prodlist *pNew=NULL,*pRun=NULL,*pTrail=NULL;
  392. Char input;
  393. char cDump;
  394. do {
  395. printf("Enter Category : ");
  396. scanf("%c",&cDump);
  397. fgets (input,16,stdin);
  398. input[strlen(input)-1]='\0';
  399. n = Getcat (stock,input,*nCat);
  400. } while (n==-1);
  401. strcpy(stock[n]->category,input);
  402. if (n==*nCat && n !=0)
  403. stock[n]->list=NULL;
  404. if (stock[n]->list==NULL)
  405. (*nCat)++;
  406. pNew=malloc(sizeof(Prodlist));
  407. Getprodinfo (pNew,stock,n);
  408. if (stock[n]->list == NULL){
  409. stock[n]->list = pNew;
  410. stock[n]->list->pNext=NULL;
  411. }
  412. else if (strcmp (stock[n]->list->supplier, pNew->supplier)>0){
  413. pNew->pNext = stock[n]->list;
  414. stock[n]->list = pNew;
  415. }
  416. else if (strcmp (stock[n]->list->supplier, pNew->supplier)==0){
  417. if (strcmp(stock[n]->list->code,pNew->code) > 0){
  418. pNew->pNext = stock[n]->list;
  419. stock[n]->list = pNew;
  420. }
  421. else{
  422. pRun = stock[n]->list;
  423. while (pRun != NULL && strcmp(pRun-> code, pNew->code) <0){
  424. pTrail = pRun;
  425. pRun = pRun->pNext;
  426. }
  427. pTrail->pNext = pNew;
  428. pNew->pNext = pRun;
  429. }
  430. }
  431. else {
  432. pRun = stock[n]->list;
  433. while (pRun != NULL && strcmp(pRun->supplier, pNew->supplier) < 0) {
  434. pTrail = pRun;
  435. pRun = pRun->pNext;
  436. }
  437. pTrail->pNext = pNew;
  438. pNew->pNext=pRun;
  439. }
  440. printf("Stock Added\n");
  441. }
  442. int Getcatindex (Stocks *stock, Char input, int nCat){
  443. int i;
  444. if (nCat==0)
  445. return -2;
  446. else {
  447. for (i=0;i<nCat;i++)
  448. if (strcmp(input,stock[i]->category)==0)
  449. return i;
  450. return -1;
  451. }
  452. }
  453. void Modifystock (Stocks *stock, int *nCat) { /* Modifys stock information */
  454. int exit =1, input, i,n,y,k;
  455. Code code;
  456. Char newcat;
  457. Prodlist *temp,*pRun,*pTrail;
  458. printf("Modify Stock");
  459. Viewallstock (stock,nCat,0);
  460. printf("Enter product code: ");
  461. scanf("%s",&code);
  462. for (i=0;i<(*nCat);i++){
  463. temp = stock[i]->list;
  464. while (temp!=NULL){
  465. if (strcmp(temp->code,code)==0){
  466. do {
  467. printf("Choose an option \n");
  468. printf("Modify Category : 1\n");
  469. printf("Modify Supplier : 2\n");
  470. printf("Modify Product : 3\n");
  471. printf("Modify Purchase Price : 4\n");
  472. printf("Modify Selling Price : 5\n");
  473. printf("Modify Discount : 6\n");
  474. printf("Finish Mod of product %s : 7\n",temp->code);
  475. scanf("%d",&input);
  476. switch (input) {
  477. case 1: printf("Enter New Category : ");
  478. fgets (newcat,16,stdin);
  479. fgets (newcat,16,stdin);
  480. newcat[strlen(newcat)-1]='\0';
  481. if (Getcatindex (stock,newcat,*nCat)==-1){
  482. strcpy(stock[*nCat]->category,newcat);
  483. if (stock[*nCat]->list == NULL){
  484. stock[*nCat]->list = temp;
  485. stock[*nCat]->list->pNext=NULL;
  486. }
  487. printf("New Category is %s\n",stock[*nCat]->category);
  488. k=1;
  489. (*nCat)++;
  490. }
  491. else {
  492. printf("NOPE IT WENT HERE \n");
  493. if (stock[Getcatindex (stock,newcat,*nCat)]->list == NULL){
  494. stock[Getcatindex (stock,newcat,*nCat)]->list = temp;
  495. stock[Getcatindex (stock,newcat,*nCat)]->list->pNext=NULL;
  496. }
  497. else if (strcmp (stock[Getcatindex (stock,newcat,*nCat)]->list->code, temp->code)>0){
  498. temp->pNext = stock[Getcatindex (stock,newcat,*nCat)]->list;
  499. stock[Getcatindex (stock,newcat,*nCat)]->list = temp;
  500. }
  501. else {
  502. pRun = stock[Getcatindex (stock,newcat,*nCat)]->list;
  503. while (pRun != NULL && strcmp(pRun->code, temp->code) < 0) {
  504. pTrail = pRun;
  505. pRun = pRun->pNext;
  506. }
  507. pTrail->pNext = temp;
  508. temp->pNext=pRun;
  509. }
  510. printf("New Category is %s\n",stock[Getcatindex(stock,newcat,*nCat)]->category);
  511. k=2;
  512. }
  513. break;
  514. case 2: printf("Enter New Supplier : ");
  515. fgets (temp->supplier,16,stdin);
  516. fgets (temp->supplier,16,stdin);
  517. temp->supplier[strlen(temp->supplier)-1]='\0';
  518. printf("New Supplier is %s\n",temp->supplier); break;
  519. case 3: printf("Enter New Product Name : ");
  520. fgets (temp->product,16,stdin);
  521. fgets (temp->product,16,stdin);
  522. temp->product[strlen(temp->product)-1]='\0';
  523. printf("New Product Name is %s\n",temp->product); break;
  524. case 4: printf("Enter New Purchase Price : ");
  525. scanf("%f",&temp->purchase);
  526. printf("New Purchase Price is %0.2f\n",temp->purchase); break;
  527. case 5: printf("Enter New Selling Price : ");
  528. scanf("%f",&temp->unit);
  529. printf("New Selling Price is %0.2f\n",temp->unit); break;
  530. case 6: printf("Enter New Discount : ");
  531. scanf("%f",&temp->discount);
  532. printf("New Discount Rate is %0.1f\n",temp->discount); break;
  533. case 7: if (k==1){
  534. if (temp->code[0]!=stock[*nCat]->category[0])
  535. temp->code[0]=stock[*nCat]->category[0];
  536. if (temp->code[1]!=temp->supplier[0])
  537. temp->code[1]=temp->supplier[0];
  538. if (temp->code[2]!=temp->product[0])
  539. temp->code[2]=temp->product[0];
  540. for (n=0;n<(*nCat);n++){
  541. if (n!=i)
  542. if (strcmp (temp->code,stock[n]->list->code)==0)
  543. for (y=3;y<8;y++)
  544. temp->code[y]= rand()%10+'0';
  545. }
  546. }
  547. if (temp->code[0]!=stock[i]->category[0])
  548. temp->code[0]=stock[i]->category[0];
  549. if (temp->code[1]!=temp->supplier[0])
  550. temp->code[1]=temp->supplier[0];
  551. if (temp->code[2]!=temp->product[0])
  552. temp->code[2]=temp->product[0];
  553. for (n=0;n<(*nCat);n++){
  554. if (n!=i)
  555. if (strcmp (temp->code,stock[n]->list->code)==0)
  556. for (y=3;y<8;y++)
  557. temp->code[y]= rand()%10+'0';
  558. }
  559. printf("New Product Code is %s \n",temp->code);
  560. exit = 0; break;
  561. }
  562. } while (exit);
  563. }
  564. temp=temp->pNext;
  565. }
  566. }
  567. }
  568. void Restock (Stocks *stock,int *nCat){ /* Restocks products */
  569. int exit = 1, input, i,change;
  570. Code code;
  571. Prodlist *temp;
  572. do {
  573. change = 0;
  574. Viewallstock (stock,nCat,0);
  575. printf("Enter Product Code : ");
  576. scanf("%s",code);
  577. printf("Enter Quantity to be added : ");
  578. scanf("%d",&input);
  579. for (i=0;i<(*nCat);i++){
  580. temp = stock[i]->list;
  581. while (temp!=NULL){
  582. if (strcmp (temp->code,code)==0){
  583. temp->quantity += input;
  584. change = 1;
  585. }
  586. temp=temp->pNext;
  587. }
  588. }
  589. if (change==0){
  590. printf("Last input product Code not found: Not restocked \n");
  591. exit = 0;
  592.  
  593. }
  594. } while (exit);
  595. }
  596. void Saveinventory (Stocks *stock, int nCat){
  597. int i;
  598. FILE * pText;
  599. Char Filename;
  600. Prodlist *temp;
  601. if (stock[0]==NULL)
  602. printf("Nothing to save \n");
  603. else {
  604. printf("Enter Filename : ");
  605. scanf("%s",Filename);
  606. pText=fopen(Filename,"wt");
  607. if(pText != NULL){
  608. for (i=0;i<nCat;i++){
  609. temp = stock[i]->list;
  610. while(temp != NULL){
  611. fprintf(pText, "%s %s %s \n%d %7.2f %s \n%7.2f&%7.2f %d \n",stock[i]->category, temp->code, temp->product, temp->quantity, temp->purchase, temp->supplier, temp->unit, temp->discount, temp->sold);
  612. if (i!=(nCat-1))
  613. fprintf(pText,"\n");
  614. temp = temp -> pNext;
  615. }
  616. }
  617. fclose(pText);
  618. }else printf("Error creating file\n");
  619. }
  620. }
  621. void Showbycat (Stocks *stock, int i,int n){
  622. Prodlist *temp;
  623. int count = 0;
  624. char cDump;
  625. if (n){
  626.  
  627. temp = stock[i]->list;
  628. while (temp!=NULL){
  629. if (count == 0)
  630. printf(" Category Supplier Product Code Product Available Sold Purchase Selling Discount\n");
  631. printf("%15s ",stock[i]->category);
  632. printf("%15s ",temp->supplier);
  633. printf("%14s ",temp->code);
  634. printf("%15s ",temp->product);
  635. printf("%9d ",temp->quantity);
  636. printf("%4d ",temp->sold);
  637. printf("%7.2f ",temp->purchase);
  638. printf("%7.2f ",temp->unit);
  639. printf("%7.2f \n",temp->discount);
  640. count++;
  641. if (count > 20) {
  642. printf("NEXT PAGE ");
  643. scanf("%c",&cDump);
  644. scanf("%c",&cDump);
  645. count = 0;
  646. }
  647. temp=temp->pNext;
  648. }
  649. }
  650. else
  651.  
  652. temp = stock[i]->list;
  653. while (temp!=NULL){
  654. if (count == 0)
  655. printf(" Category Brand Product Code Product Available Sold Unit Discount\n");
  656. printf("%15s ",stock[i]->category);
  657. printf("%15s ",temp->supplier);
  658. printf("%14s ",temp->code);
  659. printf("%15s ",temp->product);
  660. printf("%9d ",temp->quantity);
  661. printf("%4d ",temp->sold);
  662. printf("%7.2f ",temp->unit);
  663. printf("%7.2f \n",temp->discount);
  664. count++;
  665. if (count > 20) {
  666. printf("NEXT PAGE ");
  667. scanf("%c",&cDump);
  668. scanf("%c",&cDump);
  669. count = 0;
  670. }
  671. temp=temp->pNext;
  672. }
  673. }
  674. void Viewstockcat (Stocks *stock, int nCat,int i){
  675. int exit = 1;
  676. Char input;
  677. do{
  678. printf("Enter a category : ");
  679. fgets (input,16,stdin);
  680. fgets (input,16,stdin);
  681. input[strlen(input)-1]='\0';
  682. if (Getcatindex (stock,input,nCat)==-2){
  683. printf("No stocks to show \n");
  684. exit=0;
  685. }
  686. else if (Getcatindex (stock,input,nCat)==-1)
  687. printf("No Category");
  688. else {
  689. Showbycat (stock,Getcatindex (stock,input,nCat),i);
  690. exit=0;
  691. }
  692. } while (exit);
  693. }
  694. void Updateinventory (Stocks *stock, int *nCat){
  695. FILE * pFile;
  696. int i=0,valid=1,n=-1;
  697. Prodlist *temp;
  698. Char input,filename;
  699. char cDump;
  700. printf("Enter file name : ");
  701. scanf("%s",filename);
  702. if ((pFile = fopen (filename,"rt"))!=NULL){
  703. while (fscanf(pFile, "%s %s %s %d %7.2f %s %7.2f %7.2f %d",input, temp->code, temp->product, temp->quantity, temp->purchase, temp->supplier, temp->unit, temp->discount, temp->sold)==9){
  704. strcpy(stock[i]->category,input);
  705. stock[i]->list = temp;
  706. printf("IT SHOULD WORK \n");
  707. }
  708. }
  709. }
  710. void Viewreorder (Stocks *stock, int nCat){
  711. int i,count=0,print=1;
  712. Prodlist *temp;
  713. char cDump;
  714. for (i=0;i<(nCat);i++){
  715. temp = stock[i]->list;
  716. while (temp!=NULL){
  717. if (count == 0&&print)
  718. printf(" Category Supplier Product Code Product Available Sold Purchase Selling Discount\n");
  719. if (temp->quantity <= 10){
  720. printf("%15s",stock[i]->category);
  721. printf("%15s",temp->supplier);
  722. printf("%14s",temp->code);
  723. printf("%15s",temp->product);
  724. printf("%9d ",temp->quantity);
  725. printf("%4d ",temp->sold);
  726. printf("%7.2f ",temp->purchase);
  727. printf("%7.2f ",temp->unit);
  728. printf("%7.2f \n",temp->discount);
  729. print=1;
  730. count++;
  731. }
  732. else print=0;
  733. if (count > 20) {
  734. printf("NEXT PAGE ");
  735. scanf("%c",&cDump);
  736. scanf("%c",&cDump);
  737. count = 0;
  738. }
  739. temp=temp->pNext;
  740. }
  741. }
  742. }
  743. void Managestocks (Stocks *stock, int *nCat) { /* Manage stocks menu */
  744.  
  745. int exit=1,input,i;
  746. do {
  747. printf("Manage Stocks \n");
  748. printf("Choose an option \n");
  749. printf("Add new stock : 1 \n");
  750. printf("View all stocks : 2 \n");
  751. printf("View stocks by category : 3 \n");
  752. printf("View stocks to reorder : 4 \n");
  753. printf("Modify stock info : 5 \n");
  754. printf("Restock : 6 \n");
  755. printf("Save inventory : 7 \n");
  756. printf("Update inventory from file : 8 \n");
  757. printf("Return to Admin Menu : 9 \n");
  758. scanf("%d",&input);
  759. switch (input) {
  760. case 1: Addstock (stock,nCat); break;
  761. case 2: Viewallstock (stock,nCat,0); break;
  762. case 3: Viewstockcat (stock,*nCat,1); break;
  763. case 4: Viewreorder (stock,*nCat); break;
  764. case 5: Modifystock (stock,nCat); break;
  765. case 6: Restock (stock,nCat); break;
  766. case 7: Alphabeticalindex (stock,*nCat);
  767. Saveinventory (stock, *nCat); break;
  768. case 8: Updateinventory (stock, nCat); break;
  769. case 9: exit = 0;
  770. }
  771. } while (exit);
  772. }
  773. void Initializemysoul (Usertype *user){
  774. Usertype *pTrail=NULL;
  775. while (user!=NULL){
  776. if (user->type =='S'){
  777. user->pPrev = pTrail;
  778. pTrail = user;
  779. }
  780. user=user->pNext;
  781. }
  782. }
  783. void Updateoutstanding (Usertype *user,Stocks *stock, int nCat){
  784. int i,n;
  785. Prodlist *temp;
  786. float amount=0;
  787. while (user!=NULL){
  788. if (user->type=='S'&&user->nItems>0){
  789. for (n=0;n<user->nItems;n++){
  790. for (i=0;i<nCat;i++){
  791. temp = stock[i]->list;
  792. while (temp != NULL){
  793. if (strcmp (temp->code,user->cart[n].Prodcode)==0)
  794. amount += temp->unit-((temp->discount/100)*temp->unit);
  795. temp=temp->pNext;
  796. }
  797. }
  798. }
  799. user->outstanding += amount;
  800. user->nItems = 0;
  801. user->checkout = 0;
  802. }
  803. user=user->pNext;
  804. }
  805. }
  806. void Deliveryreport (Usertype *user, Stocks *stock,int nCat){
  807. int i,n,total;
  808. char input,cDump;
  809. Prodlist *temp,*temporary;
  810. FILE * pFile;
  811. Usertype *pFirst=user;
  812. float disc,amount,Outstanding;
  813. do {
  814. disc=0;
  815. amount=0;
  816. if (user->type=='S'&&user->nItems>0){
  817. printf("User ID : %s \n",user->username);
  818. printf("Customer Name : %s, %s %s \n",user->info.Userinfo.Last,user->info.Userinfo.First,user->info.Userinfo.Second);
  819. printf("Delivery Address : %s \n",user->info.Address);
  820. printf(" Product Code Product Quantity Unit Total Subtotal \n");
  821. for (n=0;n<user->nItems;n++){
  822. for(i=0;i<nCat;i++){
  823. temp = stock[i]->list;
  824. while (temp != NULL){
  825. if (strcmp (temp->code,user->cart[n].Prodcode)==0){
  826. printf("%14s ", temp->code);
  827. printf("%15s ",temp->product);
  828. printf("%10d ",user->cart[n].qty);
  829. printf("%7.2f ",temp->unit);
  830. printf("%7.2f ",temp->unit*user->cart[n].qty);
  831. printf("-%7.2f ",temp->discount);
  832. total += user->cart[n].qty;
  833. disc += (temp->discount/100)*temp->unit;
  834. amount += temp->unit-((temp->discount/100)*temp->unit);
  835. printf("%7.2f \n",temp->unit-((temp->discount/100)*temp->unit));
  836. }
  837. temp=temp->pNext;
  838. }
  839. }
  840. }
  841. Outstanding = amount + user->outstanding;
  842. printf("Number of Items : %d \n",total);
  843. printf("Total Discount : %7.2f \n",disc);
  844. printf("Bill Amount : %7.2f \n",amount);
  845. printf("Total Outstanding : %7.2f \n",Outstanding);
  846. if (user->pNext != NULL&& user->pNext->type=='S')
  847. printf("Next : N\n");
  848. if (user->pPrev != NULL)
  849. printf("Back : B\n");
  850. printf("Exit : X\n");
  851. scanf("%c",&cDump);
  852. scanf("%c",&input);
  853. if (input >= 97 && input <=122)
  854. input-=32;
  855. if (input == 'N')
  856. user=user->pNext;
  857. if (input == 'B')
  858. user=user->pPrev;
  859. }
  860. else
  861. user=user->pNext;
  862. } while (input != 'X'&&user!=NULL);
  863.  
  864. pFile =fopen ("Delivery Recipts.txt","wt");
  865. if (pFile != NULL){
  866. while (pFirst!=NULL){
  867. if (pFirst->type=='S'&&pFirst->nItems>0){
  868. fprintf(pFile,"%s %d\n",pFirst->username,pFirst->nItems);
  869. for (n=0;n<pFirst->nItems;n++){
  870. for(i=0;i<nCat;i++){
  871. temporary = stock[i]->list;
  872. while (temporary != NULL){
  873. if (strcmp (temporary->code,pFirst->cart[n].Prodcode)==0)
  874. fprintf(pFile,"%d %s %s\n@%7.2f&%7.2f\n",pFirst->cart[n].qty,temporary->code,temporary->product,temporary->unit,temporary->discount);
  875. temporary = temporary->pNext;
  876. }
  877. }
  878. }
  879. fprintf(pFile,"\n");
  880. }
  881. pFirst=pFirst->pNext;
  882. }
  883. }
  884. fclose(pFile);
  885. Updateoutstanding (user,stock,nCat);
  886.  
  887. }
  888. void Adminmenu (Usertype *user,Usertype *All,Stocks *stock, int *esc, int *nCat){ // Admin Menu
  889. int exit=1,input,i;
  890.  
  891. do {
  892. printf("ADMIN MENU \n");
  893. printf("Choose an option \n");
  894. printf("Manage Accounts: 1 \n");
  895. printf("Manage Stocks: 2 \n");
  896. printf("Prepare Delivery Report: 3 \n");
  897. printf("Shutdown Kioski: 4 \n");
  898. printf("Log out: 5 \n");
  899. scanf("%d",&input);
  900. switch (input) {
  901. case 1: Manageaccounts (All); break;
  902. case 2: Managestocks (stock,nCat); break;
  903. case 3: Initializemysoul (user);
  904. Deliveryreport (All,stock,*nCat); break;
  905. case 4: *esc = 0;
  906. case 5: exit = 0;
  907. }
  908. } while (exit);
  909. }
  910. void Changename (Userinfo *uInfo){/* Changes user information */
  911. int input;
  912. printf("Choose an option : \n");
  913. printf("Edit first name : 1 \n");
  914. printf("Edit middle name : 2\n");
  915. printf("Edit last name : 3\n");
  916. scanf("%d",&input);
  917. switch (input) {
  918. case 1: printf("Enter your First Name: ");
  919. fgets(uInfo->Userinfo.Last,MAXNAME,stdin);
  920. fgets(uInfo->Userinfo.First,MAXNAME,stdin);
  921. if (uInfo->Userinfo.First[0] >= 97 && uInfo->Userinfo.First[0] <=122)
  922. uInfo->Userinfo.First[0]-=32;
  923. uInfo->Userinfo.First[strlen(uInfo->Userinfo.First)-1]='\0';
  924. printf("Your New Name is: ");
  925. printf("%s",uInfo->Userinfo.First);
  926. break;
  927. case 2: printf("Enter your Middle Name: ");
  928. fgets(uInfo->Userinfo.Last,MAXNAME,stdin);
  929. fgets(uInfo->Userinfo.Second,MAXNAME,stdin);
  930. if (uInfo->Userinfo.Second[0] >= 97 && uInfo->Userinfo.Second[0] <=122)
  931. uInfo->Userinfo.Second[0]-=32;
  932. uInfo->Userinfo.Second[strlen(uInfo->Userinfo.Second)-1]='\0';
  933. printf("Your New Name is: ");
  934. printf("%s",uInfo->Userinfo.Second);
  935. break;
  936. case 3: printf("Enter your Last Name: ");
  937. fgets(uInfo->Userinfo.Last,MAXNAME,stdin);
  938. fgets(uInfo->Userinfo.Last,MAXNAME,stdin);
  939. if (uInfo->Userinfo.Last[0] >= 97 && uInfo->Userinfo.Last[0] <=122)
  940. uInfo->Userinfo.Last[0]-=32;
  941. uInfo->Userinfo.Last[strlen(uInfo->Userinfo.Last)-1]='\0';
  942. printf("Your New Name is: ");
  943. printf("%s",uInfo->Userinfo.Last);
  944. }
  945.  
  946. }
  947. void Changeadd (Userinfo *uInfo) { /* Changes username */
  948. printf("Enter your Address: ");
  949. fgets(uInfo->Address,MAXADD,stdin);
  950. fgets(uInfo->Address,MAXADD,stdin);
  951. printf("Your New Address is: ");
  952. printf("%s\n",uInfo->Address);
  953. }
  954. void Changepass (Usertype *user) { /* Changes password */
  955. char cDump;
  956. do{
  957. printf("Enter Password: ");
  958. scanf("%s%c",user->password,&cDump);
  959. } while (length (user)==0 || passcheck(user)==0);
  960. printf("Your new password is: ");
  961. printf("%s\n", user->password);
  962. }
  963. void Modifyinfo (Usertype *user) { /* Modifys user info */
  964. int exit = 1,input;
  965. do {
  966. printf("Modify User Menu \n");
  967. printf("Choose an option \n");
  968. printf("Change Name: 1 \n");
  969. printf("Change Address: 2 \n");
  970. printf("Change Password: 3 \n");
  971. printf("Return to Shopper Menu: 4 \n");
  972. scanf("%d",&input);
  973. switch (input) {
  974. case 1: Changename (&user->info); break;
  975. case 2: Changeadd (&user->info); break;
  976. case 3: Changepass (user); break;
  977. case 4: exit = 0;
  978. }
  979. } while (exit);
  980. }
  981. void Settlebalance (Usertype *user) { /* Pays for outstanding balance */
  982. int card,security,paid=1;
  983. float payment;
  984. printf("Your outstanding balance is %.2f \n",user->outstanding);
  985. printf("Enter your credit card number (without spaces): ");
  986. scanf("%d",&card);
  987. printf("Enter your security code: ");
  988. scanf("%d",&security);
  989. do {
  990. printf("Enter amount: ");
  991. scanf("%f",&payment);
  992. if (payment <= user->outstanding){
  993. user->outstanding -= payment;
  994. paid=0;
  995. }
  996. else
  997. printf("You entered too much!");
  998. } while (paid);
  999. printf("Your new balance is %.2f\n",user->outstanding);
  1000. }
  1001. int Checkitem (Usertype *user,Code code){
  1002. int i;
  1003. if (user->nItems==0)
  1004. return 0;
  1005. for (i=0;i<user->nItems;i++)
  1006. if (strcmp (user->cart[i].Prodcode,code)==0)
  1007. return i;
  1008. return user->nItems;
  1009. }
  1010. void Addtocart (Usertype *user, Stocks *stock,int nCat){
  1011. int exit = 1,input,quant,i,n;
  1012. Code code;
  1013. Prodlist *temp;
  1014. Viewallstock (stock,&nCat,1);
  1015. do {
  1016. printf("Enter product code : ");
  1017. scanf("%s",code);
  1018. printf("Enter quantity : ");
  1019. scanf("%d",&quant);
  1020. for (i=0;i<(nCat);i++){
  1021. temp = stock[i]->list;
  1022. while (temp!=NULL){
  1023. if (strcmp (temp->code,code)==0){
  1024. if (quant<=temp->quantity){
  1025. n = Checkitem (user,code);
  1026. user->cart[n].qty+=quant;
  1027. strcpy(user->cart[n].Prodcode,code);
  1028. if (n==user->nItems)
  1029. user->nItems++;
  1030. }
  1031. }
  1032. temp=temp->pNext;
  1033. }
  1034. }
  1035. printf("Add another product to cart? (1 = Yes or 0 = No) : ");
  1036. scanf("%d",&input);
  1037. if (!input)
  1038. exit = 0;
  1039. } while (exit);
  1040. }
  1041. void Checkout (Usertype *user, Stocks *stock,int nCat){
  1042. int n,i;
  1043. Prodlist *temp;
  1044. for (n=0;n<user->nItems;n++){
  1045. for(i=0;i<nCat;i++){
  1046. temp = stock[i]->list;
  1047. while (temp != NULL){
  1048. if (strcmp (temp->code,user->cart[n].Prodcode)==0){
  1049. temp->quantity -= user->cart[n].qty;
  1050. temp->sold += user->cart[n].qty;
  1051. }
  1052. temp = temp -> pNext;
  1053. }
  1054. }
  1055. }
  1056. user->checkout=1;
  1057. }
  1058. int getindex (Usertype *user,Code code){
  1059. int i;
  1060. for (i=0;i<user->nItems;i++)
  1061. if (strcmp (user->cart[i].Prodcode,code)==0)
  1062. return i;
  1063. }
  1064. void Removeitem (Usertype *user){
  1065. int i;
  1066. Code code;
  1067. printf("Enter product code : ");
  1068. scanf("%s",code);
  1069.  
  1070. for (i=getindex(user,code);i<user->nItems;i++)
  1071. user->cart[i]=user->cart[i+1];
  1072. user->nItems--;
  1073. }
  1074. void Removeitem2 (Usertype *user, Code code){
  1075. int i;
  1076. for (i=getindex(user,code);i<user->nItems;i++)
  1077. user->cart[i]=user->cart[i+1];
  1078. user->nItems--;
  1079. }
  1080. void Updatequantity (Usertype *user, Stocks *stock, int nCat){
  1081. int i,quant,n;
  1082. Code code;
  1083. Prodlist *temp;
  1084. printf("Enter product code : ");
  1085. scanf("%s",code);
  1086. printf("Enter quantity : ");
  1087. scanf("%d",&quant);
  1088. for (n=0;n<user->nItems;n++){
  1089. if (strcmp(user->cart[n].Prodcode,code)==0){
  1090. for (i=0;i<nCat;i++){
  1091. temp=stock[i]->list;
  1092. while (temp != NULL){
  1093. if (strcmp (temp->code,user->cart[n].Prodcode)==0){
  1094. if (quant == 0)
  1095. Removeitem2 (user,code);
  1096. else if (quant<=temp->quantity)
  1097. user->cart[n].qty+=quant;
  1098. else
  1099. printf("Not enough \n");
  1100. }
  1101. temp=temp->pNext;
  1102. }
  1103. }
  1104. }
  1105. }
  1106. }
  1107. void Editcart (Usertype *user,Stocks *stock,int nCat){
  1108. int exit =1, input;
  1109. do{
  1110. printf("Choose an option : \n");
  1111. printf("Remove an item : 1\n");
  1112. printf("Update Quantity : 2\n");
  1113. printf("Return : 3\n");
  1114. scanf("%d",&input);
  1115. switch (input){
  1116. case 1: Removeitem(user);
  1117. case 2: Updatequantity(user,stock,nCat);
  1118. case 3: exit = 0; break;
  1119. }
  1120. } while (exit);
  1121. }
  1122. void Viewcart (Usertype *user, Stocks *stock, int nCat){
  1123. int i,total=0,n,input;
  1124. Prodlist *temp;
  1125. float disc=0,amount=0;
  1126. printf(" Product Code Product Quantity Unit Total Subtotal \n");
  1127. for (n=0;n<user->nItems;n++){
  1128. for(i=0;i<nCat;i++){
  1129. temp = stock[i]->list;
  1130. while (temp != NULL){
  1131. if (strcmp (temp->code,user->cart[n].Prodcode)==0){
  1132. printf("%14s ", temp->code);
  1133. printf("%15s ",temp->product);
  1134. printf("%10d ",user->cart[n].qty);
  1135. printf("%7.2f ",temp->unit);
  1136. printf("%7.2f ",temp->unit*user->cart[n].qty);
  1137. printf("-%7.2f ",temp->discount);
  1138. total += user->cart[n].qty;
  1139. disc += (temp->discount/100)*temp->unit;
  1140. amount += temp->unit-((temp->discount/100)*temp->unit);
  1141. printf("%7.2f \n",temp->unit-((temp->discount/100)*temp->unit));
  1142. }
  1143. temp=temp->pNext;
  1144. }
  1145. }
  1146. }
  1147. printf("Number of Items : %d \n",total);
  1148. printf("Total Discount : %.2f\n",disc);
  1149. printf("Cart Amount : %.2f\n",amount);
  1150. printf("\n");
  1151. printf("Choose an option \n");
  1152. printf("Check out : 1\n");
  1153. printf("Edit cart items : 2\n");
  1154. printf("Back to shopper menu : 3\n");
  1155. scanf("%d",&input);
  1156. switch (input) {
  1157. case 1: Checkout (user,stock,nCat); break;
  1158. case 2: Editcart (user,stock,nCat);
  1159. case 3: break;
  1160. }
  1161. }
  1162. void Viewstocksale (Stocks *stock, int nCat){
  1163. int i,count=0,print=1;
  1164. Prodlist *temp;
  1165. char cDump;
  1166. for (i=0;i<(nCat);i++){
  1167. temp = stock[i]->list;
  1168. while (temp!=NULL){
  1169. if (count == 0&&print)
  1170. printf(" Category Brand Product Code Product Available Sold Unit Discount\n");
  1171. if (temp->discount>0){
  1172. printf("%15s ",stock[i]->category);
  1173. printf("%15s ",temp->supplier);
  1174. printf("%14s ",temp->code);
  1175. printf("%15s ",temp->product);
  1176. printf("%9d ",temp->quantity);
  1177. printf("%4d ",temp->sold);
  1178. printf("%7.2f ",temp->unit);
  1179. printf("%7.2f \n",temp->discount);
  1180. print=1;
  1181. count++;
  1182. }
  1183. else print=0;
  1184. if (count > 20) {
  1185. printf("NEXT PAGE ");
  1186. scanf("%c",&cDump);
  1187. scanf("%c",&cDump);
  1188. count = 0;
  1189. }
  1190. temp=temp->pNext;
  1191. }
  1192. }
  1193. }
  1194. void Shoppermenu (Usertype *user,Stocks *stock, int nCat){ /* Shopper Menu */
  1195. int exit = 1,input;
  1196. do {
  1197. printf("Shopper Menu \n");
  1198. printf("Hello %s\n", user->info.Userinfo.First);
  1199. printf("Choose an option \n");
  1200. printf("Modify User Info: 1 \n");
  1201. printf("Browse All Products: 2 \n");
  1202. printf("Browse Products by Category: 3 \n");
  1203. printf("Browse Products on Sale: 4 \n");
  1204. if (user->outstanding<user->credlimit&&user->checkout==0)
  1205. printf("Add to Cart: 5 \n");
  1206. if (user->nItems>0)
  1207. printf("View Cart: 6 \n");
  1208. if (user->outstanding != 0.00)
  1209. printf("Settle Outstanding Balance: 7 \n");
  1210. printf("Log out: 8 \n");
  1211. scanf ("%d",&input);
  1212. switch (input) {
  1213. case 1: Modifyinfo (user); break;
  1214. case 2: Viewallstock (stock,&nCat,1); break;
  1215. case 3: Viewstockcat (stock,nCat,0); break;
  1216. case 4: Viewstocksale (stock,nCat); break;
  1217. case 5: Addtocart (user,stock,nCat); break;
  1218. case 6: Viewcart (user,stock,nCat); break;
  1219. case 7: Settlebalance (user); break;
  1220. case 8: exit = 0;
  1221. }
  1222. } while (exit);
  1223. }
  1224. void freeAll (ptrUser *pUser,Stocks *stock,int nCat) { /* Frees all data */
  1225. int i;
  1226. ptrUser pTemp;
  1227. Prodlist *temp,*Free;
  1228. while ((*pUser) != NULL){
  1229. pTemp= *pUser;
  1230. *pUser = (*pUser)->pNext;
  1231. free(pTemp);
  1232. }
  1233. for (i=0;i<nCat;i++){
  1234. temp=stock[i]->list;
  1235. while (temp!=NULL){
  1236. Free = temp;
  1237. temp=temp->pNext;
  1238. free(Free);
  1239. }
  1240. }
  1241. }
  1242. int main () {
  1243. int exit=1,input, nCat = 0,i,checkout=1;
  1244. Usertype user;
  1245. ptrUser pUsers = NULL, pNew, pLast, pAccount, pRun, pTrail;
  1246. Stocks stock;
  1247. stock[0].list=NULL;
  1248. do {
  1249. printf("Main Menu \n");
  1250. printf("Choose an option: \n");
  1251. printf("Log-in : 1\n");
  1252. printf("Sign-up : 2\n");
  1253. scanf("%d",&input);
  1254. switch (input){
  1255. case 1: if (login (pUsers,&pAccount)){
  1256. if (pAccount->type == 'S')
  1257. Shoppermenu (pAccount,&stock,nCat);
  1258. if (pAccount->type == 'A')
  1259. Adminmenu (pAccount,pUsers,&stock,&exit,&nCat);
  1260. } break;
  1261. case 2: pNew = malloc(sizeof(Usertype));
  1262. Signup (pNew,pUsers);
  1263. pNew->pNext = NULL;
  1264. pNew->pPrev =NULL;
  1265. if (pUsers == NULL)
  1266. pUsers = pNew;
  1267. else if (strcmp (pUsers->username, pNew->username)>0){
  1268. pNew->pNext = pUsers;
  1269. pUsers = pNew;
  1270. }
  1271. else {
  1272. pRun = pUsers ;
  1273. while (pRun != NULL && strcmp(pRun->username, pNew->username) < 0) {
  1274. pTrail = pRun;
  1275. pRun = pRun->pNext;
  1276. }
  1277. pTrail->pNext = pNew;
  1278. pNew->pNext=pRun;
  1279. }
  1280. break;
  1281. case 3: Managestocks (&stock,&nCat); break;
  1282. }
  1283. } while (exit);
  1284. freeAll(&pUsers,&stock,nCat);
  1285. return 0;
  1286. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement