Advertisement
Guest User

Final

a guest
Mar 12th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.72 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. typedef char Char [MAXCHAR];
  19. typedef char Name [MAXNAME];
  20. typedef char Add [MAXADD];
  21. typedef char Code [MAXCODE];
  22. typedef char Adcd [MAXCODE];
  23. typedef struct {
  24. Name First;
  25. Name Second;
  26. Name Last;
  27. }sName;
  28. typedef struct {
  29. sName Userinfo;
  30. Add Address;
  31. }Userinfo;
  32. typedef struct {
  33. Code Prodcode;
  34. int qty;
  35. }ProductTag;
  36. typedef ProductTag arrBought[MAXCART];
  37. typedef struct Usertag {
  38. Char username;
  39. Char password;
  40. Userinfo info;
  41. char type;
  42. float credlimit;
  43. float outstanding;
  44. arrBought cart;
  45. int nItems;
  46. int count;
  47. struct Usertag *pNext;
  48. };
  49. typedef struct Usertag Usertype;
  50. typedef Usertype * ptrUser;
  51. typedef struct {
  52. Char supplier;
  53. Char product;
  54. int quantity;
  55. float purchase;
  56. float unit;
  57. float discount;
  58. int sold;
  59. Code code;
  60. }Productlist;
  61. typedef struct {
  62. Char category;
  63. Productlist list;
  64. }Stock;
  65. typedef Stock Stocks[10];
  66.  
  67. void getUserinfo (Userinfo *uInfo){
  68. printf("Enter your First Name: ");
  69. fgets(uInfo->Userinfo.First ,MAXNAME,stdin);
  70. printf("Enter your Middle Name: ");
  71. fgets(uInfo->Userinfo.Second,MAXNAME,stdin);
  72. printf("Enter your Last Name: ");
  73. fgets(uInfo->Userinfo.Last,MAXNAME,stdin);
  74. printf("Enter your Address: ");
  75. fgets(uInfo->Address,MAXADD,stdin);
  76. uInfo->Userinfo.Last[strlen(uInfo->Userinfo.Last)-1]='\0';
  77. uInfo->Userinfo.First[strlen(uInfo->Userinfo.First)-1]='\0';
  78. uInfo->Userinfo.Second[strlen(uInfo->Userinfo.Second)-1]='\0';
  79. if (uInfo->Userinfo.First[0] >= 97 && uInfo->Userinfo.First[0] <=122)
  80. uInfo->Userinfo.First[0]-=32;
  81. if (uInfo->Userinfo.Second[0] >= 97 && uInfo->Userinfo.Second[0] <=122)
  82. uInfo->Userinfo.Second[0]-=32;
  83. if (uInfo->Userinfo.Last[0] >= 97 && uInfo->Userinfo.Last[0] <=122)
  84. uInfo->Userinfo.Last[0]-=32;
  85. printf("Your Name is: ");
  86. printf("%s, %s %s\n",uInfo->Userinfo.Last,uInfo->Userinfo.First,uInfo->Userinfo.Second);
  87. printf("Your Address is: ");
  88. printf("%s\n",uInfo->Address);
  89. }
  90. int passcheck (Usertype *user){
  91. int i,count=0;
  92. for (i=0;i<strlen(user->password);i++)
  93. if ((user->password[i] < 'A' || user->password[i] > 'Z'))
  94. if ((user->password[i] < 'a' || user->password[i] > 'z'))
  95. count++;
  96. if (count==0)
  97. printf("You must have at least 1 non-letter character\n");
  98. return count;
  99. }
  100. int length (Usertype *user){
  101. if (strlen (user->password) < 6){
  102.  
  103. printf("password is too short \n");
  104. return 0;
  105. }
  106.  
  107. else if (strlen (user->password) > 15){
  108. printf("password is too long \n");
  109. return 0;
  110. }
  111. else return 1;
  112. }
  113. int Useravailable (Usertype *user, char input[]) {
  114. ptrUser pTemp;
  115. while (user != NULL) {
  116. pTemp = user;
  117. user = user->pNext;
  118. if (strcmp (input,pTemp->username)==0){
  119. printf("Your username is taken. Enter another \n");
  120. return 1;
  121. }
  122. }
  123. return 0;
  124. }
  125. void Signup (Usertype *user, Usertype *list){
  126. char cDump;
  127. Adcd Admincode;
  128. Char input;
  129.  
  130. do{
  131. printf("Username must be 3-15 characters long\n");
  132. printf("Enter Username: ");
  133. scanf("%s%c",&input,&cDump);
  134. } while (Useravailable (list,input) || (strlen (input) < 3|| strlen(input) > 15));
  135. strcpy(user->username,input);
  136.  
  137. do{
  138. printf("Password must be 6-15 characters long and have 1 non letter character\n");
  139. printf("Enter Password: ");
  140. scanf("%s%c",user->password,&cDump);
  141. } while (length (user)==0 || passcheck(user)==0);
  142.  
  143. getUserinfo (&user->info);
  144. printf("Enter account type [S]hopper or [A]dmin : ");
  145. scanf("%c",&user->type);
  146. if (user->type=='s'|| user->type=='S'){
  147. user->credlimit = 5000.00;
  148. user->outstanding = 0.00;
  149. user->nItems = 0;
  150. user->type = 'S';
  151. printf("Credit limit: %0.2f \n",user->credlimit);
  152. printf("Outstanding balance: %0.2f \n",user->outstanding);
  153. printf("Your cart is empty \n");
  154. }
  155. else if (user->type == 'a' || user->type == 'A'){
  156. printf("Enter Admin Code: \n");
  157. do{
  158. scanf("%s",Admincode);
  159. if (strcmp(Admincode,"DLSU2017")==0)
  160. user->type = 'A';
  161. else printf("Wrong code,try again \n");
  162. } while (strcmp(Admincode,"DLSU2017")!=0);
  163. }
  164. user->count=0;
  165. }
  166. int login (ptrUser user, ptrUser *pAccount) {
  167. Char input;
  168. ptrUser pTemp,pFirst=user;
  169. if (user == NULL){
  170. printf("No Users, please sign up\n");
  171. return 0;
  172. }
  173. do {
  174. printf("Enter Username: ");
  175. scanf("%s",&input);
  176. while (user != NULL) {
  177. pTemp = user;
  178. user = user->pNext;
  179. if (strcmp (pTemp->username, input )==0){
  180. printf("USERNAME FOUND: %s \n",pTemp->username);
  181. if (pTemp->count < 3){
  182. do {
  183. printf("Enter Password: ");
  184. scanf("%s",&input);
  185. if (strcmp (pTemp->password, input)!=0){
  186. printf("Try again, %d tries left\n",3-pTemp->count);
  187. pTemp->count++;
  188. }
  189. } while (pTemp->count < 4 && strcmp (pTemp->password,input) != 0);
  190. }
  191. printf("SUCCESFUL %s \n",pTemp->username);
  192. if (strcmp(pTemp->password, input) == 0){
  193. *pAccount = pTemp;
  194. return 1;
  195. }
  196. else if (pTemp->count > 3) {
  197. printf("Your account has been locked, contact an admin \n");
  198. return 0;
  199. }
  200. }
  201. }
  202. user=pFirst;
  203. } while (strcmp (user->username,input));
  204. return 0;
  205. }
  206. void displayAll (ptrUser pUser){
  207. while (pUser != NULL) {
  208. printf("%s\n",pUser->username);
  209. pUser=pUser->pNext;
  210. }
  211. }
  212. void Displaylock (Usertype *user){
  213. printf("Locked Accounts \n");
  214. while (user != NULL) {
  215. if (user->count > 3)
  216. printf("%s\n",user->username);
  217. user = user->pNext;
  218. }
  219. }
  220. ptrUser search (ptrUser pFirst, Char username){
  221. ptrUser pRun;
  222. pRun = pFirst;
  223. while (pRun != NULL && strcmp(username,pRun->username) != 0)
  224. pRun = pRun->pNext;
  225. return pRun;
  226. }
  227. void Unlockaccount (Usertype *user) {
  228. Char input;
  229. ptrUser pTemp;
  230. printf("Enter Account to Unlock \n");
  231. scanf("%s",&input);
  232. pTemp=search (user,input);
  233. pTemp->count = 0;
  234. printf("Account of %s has been unlocked \n",pTemp->username);
  235. }
  236. void Unlockall (Usertype *user) {
  237. while (user != NULL) {
  238. if (user->count > 3)
  239. user->count = 0;
  240. user = user->pNext;
  241. }
  242. printf("All Accounts Unlocked \n");
  243. }
  244. void Viewaccounts (Usertype *user) {
  245. while (user != NULL) {
  246. if (user->outstanding)
  247. printf("%s has an outstanding balance of %0.2f \n",user->username,user->outstanding);
  248. user = user->pNext;
  249. }
  250. }
  251. void Manageaccounts (Usertype *user) {
  252. int exit=1,input;
  253. do {
  254. printf("Manage Accounts \n");
  255. printf("Choose an option \n");
  256. printf("View Locked Accounts : 1 \n");
  257. printf("Unlock Specific Account : 2 \n");
  258. printf("Unlock All Locked Accounts : 3 \n");
  259. printf("View Accounts With Outstanding Balance : 4 \n");
  260. printf("Return to Admin Menu : 5 \n");
  261. scanf("%d",&input);
  262. switch (input) {
  263. case 1: Displaylock (user); break;
  264. case 2: Unlockaccount (user); break;
  265. case 3: Unlockall (user); break;
  266. case 4: Viewaccounts (user); break;
  267. case 5: exit = 0; break;
  268. }
  269. }while (exit);
  270. }
  271. void Viewallstock (Stocks *stock, int *nCat) {
  272. int i,n;
  273. printf("Viewing All Stock\n");
  274. printf(" Category | Supplier | Product Code | Product | Available | Sold | Purchase | Selling | Discount\n");
  275. for (i=0;i<(*nCat);i++){
  276. printf(" %s ",stock[i]->category);
  277. for (n=0;n<(15-strlen(stock[i]->category));n++)
  278. printf(" ");
  279. printf("%s ",stock[i]->list.supplier);
  280. for (n=0;n<(15-strlen(stock[i]->list.supplier));n++)
  281. printf(" ");
  282. printf("%s ",stock[i]->list.code);
  283. printf("%s",stock[i]->list.product);
  284. for (n=0;n<(15-strlen(stock[i]->list.product));n++)
  285. printf(" ");
  286. if (stock[i]->list.quantity>999)
  287. printf("%d ",stock[i]->list.quantity);
  288. else if (stock[i]->list.quantity>99)
  289. printf(" %d ",stock[i]->list.quantity);
  290. else if (stock[i]->list.quantity>9)
  291. printf(" %d ",stock[i]->list.quantity);
  292. else
  293. printf(" %d ",stock[i]->list.quantity);
  294. if (stock[i]->list.sold>999)
  295. printf("%d ",stock[i]->list.sold);
  296. else if (stock[i]->list.sold>99)
  297. printf(" %d ",stock[i]->list.sold);
  298. else if (stock[i]->list.sold>9)
  299. printf(" %d ",stock[i]->list.sold);
  300. else
  301. printf(" %d ",stock[i]->list.sold);
  302. printf("\t");
  303. printf("%0.2f ",stock[i]->list.purchase); printf("\t");
  304. printf("%0.2f ",stock[i]->list.unit); printf("\t");
  305. printf("%0.1f \n",stock[i]->list.discount);
  306.  
  307. }
  308. }
  309. void Addstock (Stocks *stock,int *nCat) {
  310. int i,valid=1,n;
  311. Char input;
  312. do {
  313. printf("Enter Category : ");
  314. fgets (input,16,stdin);
  315. fgets (input,16,stdin);
  316. } while (strlen(input)< 3 || strlen(input)> 15);
  317. strcpy(stock[*nCat]->category,input);
  318. printf("Enter Supplier : ");
  319. fgets (stock[*nCat]->list.supplier,16,stdin);
  320. printf("Enter Product : ");
  321. fgets (stock[*nCat]->list.product,16,stdin);
  322. printf("Enter Quantity Available : ");
  323. scanf("%d",&stock[*nCat]->list.quantity);
  324. printf("Enter Purchase Price : ");
  325. scanf("%f",&stock[*nCat]->list.purchase);
  326. printf("Enter Unit Selling Price : ");
  327. scanf("%f",&stock[*nCat]->list.unit);
  328. printf("Enter Discount Rate : ");
  329. scanf("%f",&stock[*nCat]->list.discount);
  330. stock[*nCat]->list.sold = 0;
  331. stock[*nCat]->list.code[0] = stock[*nCat]->category[0];
  332. stock[*nCat]->list.code[1] = stock[*nCat]->list.supplier[0];
  333. stock[*nCat]->list.code[2] = stock[*nCat]->list.product[0];
  334. for (i=3;i<8;i++)
  335. stock[*nCat]->list.code[i] = rand() % 10 + '0';
  336. stock[*nCat]->category[strlen(stock[*nCat]->category)-1] = '\0';
  337. stock[*nCat]->list.supplier[strlen(stock[*nCat]->list.supplier)-1] ='\0';
  338. stock[*nCat]->list.product [strlen(stock[*nCat]->list.product)-1] = '\0';
  339. stock[*nCat]->list.code[8] = '\0';
  340. printf("Stock Added\n");
  341. (*nCat)++;
  342.  
  343. }
  344. void Modifystock (Stocks *stock, int *nCat) {
  345. int exit =1, input, i,n,y;
  346. Code code;
  347. printf("Modify Stock");
  348. Viewallstock (stock,nCat);
  349. printf("Enter product code: ");
  350. scanf("%s",&code);
  351. for (i=0;i<(*nCat);i++){
  352. if (strcmp(stock[i]->list.code,code)==0){
  353. do {
  354. printf("Choose an option \n");
  355. printf("Modify Category : 1\n");
  356. printf("Modify Supplier : 2\n");
  357. printf("Modify Product : 3\n");
  358. printf("Modify Purchase Price : 4\n");
  359. printf("Modify Selling Price : 5\n");
  360. printf("Modify Discount : 6\n");
  361. printf("Finish Mod of product %s : 7\n",stock[i]->list.code);
  362. scanf("%d",&input);
  363. switch (input) {
  364. case 1: printf("Enter New Category : ");
  365. fgets (stock[i]->category,16,stdin);
  366. fgets (stock[i]->category,16,stdin);
  367. printf("New Category is %s\n",stock[i]->category); break;
  368. case 2: printf("Enter New Supplier : ");
  369. fgets (stock[i]->list.supplier,16,stdin);
  370. fgets (stock[i]->list.supplier,16,stdin);
  371. printf("New Supplier is %s\n",stock[i]->list.supplier); break;
  372. case 3: printf("Enter New Product Name : ");
  373. fgets (stock[i]->list.product,16,stdin);
  374. fgets (stock[i]->list.product,16,stdin);
  375. printf("New Product Name is %s\n",stock[i]->list.product); break;
  376. case 4: printf("Enter New Purchase Price : ");
  377. scanf("%f",&stock[i]->list.purchase);
  378. printf("New Purchase Price is %0.2f\n",stock[i]->list.purchase); break;
  379. case 5: printf("Enter New Selling Price : ");
  380. scanf("%f",&stock[i]->list.unit);
  381. printf("New Selling Price is %0.2f\n",stock[i]->list.unit); break;
  382. case 6: printf("Enter New Discount : ");
  383. scanf("%f",&stock[i]->list.discount);
  384. printf("New Discount Rate is %0.1f\n",stock[i]->list.discount); break;
  385. case 7: if (stock[i]->list.code[0]!=stock[i]->category[0])
  386. stock[i]->list.code[0]=stock[i]->category[0];
  387. if (stock[i]->list.code[1]!=stock[i]->list.supplier[0])
  388. stock[i]->list.code[1]=stock[i]->list.supplier[0];
  389. if (stock[i]->list.code[2]!=stock[i]->list.product[0])
  390. stock[i]->list.code[2]=stock[i]->list.product[0];
  391. for (n=0;n<(*nCat);n++){
  392. if (n!=i)
  393. if (strcmp (stock[i]->list.code,stock[n]->list.code)==0)
  394. for (y=3;y<9;y++)
  395. stock[i]->list.code[y]= rand()%10+'0';
  396. }
  397. printf("Product Code is %s \n",stock[i]->list.code);
  398. exit = 0; break;
  399. }
  400. } while (exit);
  401. }
  402. }
  403. }
  404. void Restock (Stocks *stock,int *nCat){
  405. int exit = 1, input, i,change;
  406. Code code;
  407. do {
  408. change = 0;
  409. Viewallstock (stock,nCat);
  410. printf("Enter Product Code : ");
  411. scanf("%s",code);
  412. printf("Enter Quantity to be added : ");
  413. scanf("%d",&input);
  414. for (i=0;i<(*nCat);i++)
  415. if (strcmp (stock[i]->list.code,code)==0){
  416. stock[i]->list.quantity += input;
  417. change = 1;
  418. }
  419. if (i = (*nCat) && change==0)
  420. exit = 0;
  421.  
  422. } while (exit);
  423. }
  424. void Managestocks (Stocks *stock, int *nCat) {
  425. int exit=1,input;
  426. do {
  427. printf("Manage Stocks \n");
  428. printf("Choose an option \n");
  429. printf("Add new stock : 1 \n");
  430. printf("View all stocks : 2 \n");
  431. printf("View stocks by category : 3 \n");
  432. printf("View stocks to reorder : 4 \n");
  433. printf("Modify stock info : 5 \n");
  434. printf("Restock : 6 \n");
  435. printf("Save inventory : 7 \n");
  436. printf("Update inventory from file : 8 \n");
  437. printf("Return to Admin Menu : 9 \n");
  438. scanf("%d",&input);
  439. switch (input) {
  440. case 1: Addstock (stock,nCat); break;
  441. case 2: Viewallstock (stock,nCat); break;
  442. // case 3: Viewstockcat (stock); break;
  443. // case 4: Viewreorder (stock); break;
  444. case 5: Modifystock (stock,nCat); break;
  445. case 6: Restock (stock,nCat); break;
  446. // case 7: Saveinventory (stock); break;
  447. // case 8: Updateinventory (stock); break;
  448. case 9: exit = 0;
  449. }
  450. } while (exit);
  451. }
  452. void Adminmenu (Usertype *user,Usertype *All,Stocks *stock, int *esc, int *nCat){
  453. int exit=1,input;
  454. do {
  455. printf("ADMIN MENU \n");
  456. printf("Choose an option \n");
  457. printf("Manage Accounts: 1 \n");
  458. printf("Manage Stocks: 2 \n");
  459. printf("Prepare Delivery Report: 3 \n");
  460. printf("Shutdown Kioski: 4 \n");
  461. printf("Log out: 5 \n");
  462. scanf("%d",&input);
  463. switch (input) {
  464. case 1: Manageaccounts (All); break;
  465. case 2: Managestocks (stock,nCat); break;
  466. // case 3: Deliveryreport (user);
  467. case 4: *esc = 0;
  468. case 5: exit = 0;
  469. }
  470. } while (exit);
  471. }
  472. void Changename (Userinfo *uInfo){
  473. printf("Enter your First Name: ");
  474. fgets(uInfo->Userinfo.First,MAXNAME,stdin);
  475. fgets(uInfo->Userinfo.First,MAXNAME,stdin);
  476. printf("Enter your Middle Name: ");
  477. fgets(uInfo->Userinfo.Second,MAXNAME,stdin);
  478. printf("Enter your Last Name: ");
  479. fgets(uInfo->Userinfo.Last,MAXNAME,stdin);
  480. uInfo->Userinfo.Last[strlen(uInfo->Userinfo.Last)-1]='\0';
  481. uInfo->Userinfo.First[strlen(uInfo->Userinfo.First)-1]='\0';
  482. uInfo->Userinfo.Second[strlen(uInfo->Userinfo.Second)-1]='\0';
  483. if (uInfo->Userinfo.First[0] >= 97 && uInfo->Userinfo.First[0] <=122)
  484. uInfo->Userinfo.First[0]-=32;
  485. if (uInfo->Userinfo.Second[0] >= 97 && uInfo->Userinfo.Second[0] <=122)
  486. uInfo->Userinfo.Second[0]-=32;
  487. if (uInfo->Userinfo.Last[0] >= 97 && uInfo->Userinfo.Last[0] <=122)
  488. uInfo->Userinfo.Last[0]-=32;
  489. printf("Your New Name is: ");
  490. printf("%s, %s %s\n",uInfo->Userinfo.Last,uInfo->Userinfo.First,uInfo->Userinfo.Second);
  491. }
  492. void Changeadd (Userinfo *uInfo) {
  493. printf("Enter your Address: ");
  494. fgets(uInfo->Address,MAXADD,stdin);
  495. fgets(uInfo->Address,MAXADD,stdin);
  496. printf("Your New Address is: ");
  497. printf("%s\n",uInfo->Address);
  498. }
  499. void Changepass (Usertype *user) {
  500. char cDump;
  501. do{
  502. printf("Enter Password: ");
  503. scanf("%s%c",user->password,&cDump);
  504. } while (length (user)==0 || passcheck(user)==0);
  505. printf("Your new password is: ");
  506. printf("%s\n", user->password);
  507. }
  508. void Modifyinfo (Usertype *user) {
  509. int exit = 1,input;
  510. do {
  511. printf("Modify User Menu \n");
  512. printf("Choose an option \n");
  513. printf("Change Name: 1 \n");
  514. printf("Change Address: 2 \n");
  515. printf("Change Password: 3 \n");
  516. printf("Return to Shopper Menu: 4 \n");
  517. scanf("%d",&input);
  518. switch (input) {
  519. case 1: Changename (&user->info); break;
  520. case 2: Changeadd (&user->info); break;
  521. case 3: Changepass (user); break;
  522. case 4: exit = 0;
  523. }
  524. } while (exit);
  525. }
  526. void Settlebalance (Usertype *user) {
  527. int card,security,paid=1;
  528. float payment;
  529. printf("Your outstanding balance is %.2f \n",user->outstanding);
  530. printf("Enter your credit card number (without spaces): ");
  531. scanf("%d",&card);
  532. printf("Enter your security code: ");
  533. scanf("%d",&security);
  534. do {
  535. printf("Enter amount: ");
  536. scanf("%f",&payment);
  537. if (payment <= user->outstanding){
  538. user->outstanding -= payment;
  539. paid=0;
  540. }
  541. else
  542. printf("You entered too much!");
  543. } while (paid);
  544. printf("Your new balance is %.2f\n",user->outstanding);
  545. }
  546. void Viewallprod (Stocks *stock, int *nCat){
  547. int i,n;
  548. printf("Viewing All Stock\n");
  549. printf(" Category | Brand | Product Code | Product | Available | Sold | Price | Discount\n");
  550. for (i=0;i<(*nCat);i++){
  551. if (stock[i]->list.quantity > 0) {
  552. printf(" %s ",stock[i]->category);
  553. for (n=0;n<(15-strlen(stock[i]->category));n++)
  554. printf(" ");
  555. printf("%s ",stock[i]->list.supplier);
  556. for (n=0;n<(15-strlen(stock[i]->list.supplier));n++)
  557. printf(" ");
  558. printf("%s\t",stock[i]->list.code);
  559. printf("%s ",stock[i]->list.product);
  560. for (n=0;n<(15-strlen(stock[i]->list.product));n++)
  561. printf(" ");
  562. if (stock[i]->list.quantity>999)
  563. printf("%d ",stock[i]->list.quantity);
  564. else if (stock[i]->list.quantity>99)
  565. printf(" %d ",stock[i]->list.quantity);
  566. else if (stock[i]->list.quantity>9)
  567. printf(" %d ",stock[i]->list.quantity);
  568. else
  569. printf(" %d ",stock[i]->list.quantity);
  570. if (stock[i]->list.sold>999)
  571. printf("%d ",stock[i]->list.sold);
  572. else if (stock[i]->list.sold>99)
  573. printf(" %d ",stock[i]->list.sold);
  574. else if (stock[i]->list.sold>9)
  575. printf(" %d ",stock[i]->list.sold);
  576. else
  577. printf(" %d ",stock[i]->list.sold);
  578. printf("\t");
  579. printf("%0.2f ",stock[i]->list.unit); printf("\t");
  580. printf("%0.1f \n",stock[i]->list.discount);
  581. }
  582. }
  583. }
  584. void Shoppermenu (Usertype *user,Stocks *stock, int nCat){
  585. int exit = 1,input;
  586. do {
  587. printf("Shopper Menu \n");
  588. printf("Hello %s\n", user->info.Userinfo.First);
  589. printf("Choose an option \n");
  590. printf("Modify User Info: 1 \n");
  591. printf("Browse All Products: 2 \n");
  592. printf("Browse Products by Category: 3 \n");
  593. printf("Browse Products on Sale: 4 \n");
  594. printf("Add to Cart: 5 \n");
  595. printf("View Cart: 6 \n");
  596. if (user->outstanding != 0.00)
  597. printf("Settle Outstanding Balance: 7 \n");
  598. printf("Log out: 8 \n");
  599. scanf ("%d",&input);
  600. switch (input) {
  601. case 1: Modifyinfo (user); break;
  602. case 2: Viewallprod (stock,&nCat); break;
  603. case 3:
  604. case 4:
  605. case 5:
  606. case 6:
  607. case 7: Settlebalance (user); break;
  608. case 8: exit = 0;
  609. }
  610. } while (exit);
  611. }
  612.  
  613. void freeAll (ptrUser *pUser) {
  614. ptrUser pTemp;
  615. while ((*pUser) != NULL){
  616. pTemp= *pUser;
  617. *pUser = (*pUser)->pNext;
  618. free(pTemp);
  619. }
  620. }
  621. int main () {
  622. int exit=1,input, nCat = 0;
  623. Usertype user;
  624. ptrUser pUsers = NULL, pNew, pLast, pAccount, pRun, pTrail;
  625. Stocks stock;
  626. do {
  627. printf("Main Menu \n");
  628. printf("Choose an option: \n");
  629. printf("Log-in : 1\n");
  630. printf("Sign-up : 2\n");
  631. scanf("%d",&input);
  632. switch (input){
  633. case 1: if (login (pUsers,&pAccount)){
  634. if (pAccount->type == 'S')
  635. Shoppermenu (pAccount,&stock,nCat);
  636. if (pAccount->type == 'A')
  637. Adminmenu (pAccount,pUsers,&stock,&exit,&nCat);
  638. } break;
  639. case 2: pNew = malloc(sizeof(Usertype));
  640. Signup (pNew,pUsers);
  641. pNew->pNext = NULL ;
  642. if (pUsers == NULL)
  643. pUsers = pNew;
  644. else if (strcmp (pUsers->username, pNew->username)>0){
  645. pNew->pNext = pUsers;
  646. pUsers = pNew;
  647. }
  648. else {
  649. pRun = pUsers ;
  650. while (pRun != NULL && strcmp(pRun->username, pNew->username) < 0) {
  651. pTrail = pRun;
  652. pRun = pRun->pNext;
  653. }
  654. pTrail->pNext = pNew;
  655. pNew->pNext=pRun;
  656. }
  657. break;
  658. case 3: displayAll (pUsers); break;
  659.  
  660. }
  661. } while (exit);
  662. freeAll(&pUsers);
  663. return 0;
  664. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement