Guest User

FUCK ME

a guest
Mar 5th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #define MAXCHAR 16
  5. #define MAXADD 51
  6. #define MAXNAME 21
  7. #define MAXCODE 9
  8. #define MAXCART 100
  9. typedef char Char [MAXCHAR];
  10. typedef char Name [MAXNAME];
  11. typedef char Add [MAXADD];
  12. typedef char Code [MAXCODE];
  13. typedef char Adcd [MAXCODE];
  14. typedef struct {
  15. Name First;
  16. Name Second;
  17. Name Last;
  18. }sName;
  19. typedef struct {
  20. sName Userinfo;
  21. Add Address;
  22. }Userinfo;
  23. typedef struct {
  24. Code Prodcode;
  25. int qty;
  26. }ProductTag;
  27. typedef ProductTag arrBought[MAXCART];
  28. typedef struct Usertag {
  29. Char username;
  30. Char password;
  31. Userinfo info;
  32. char type;
  33. float credlimit;
  34. float outstanding;
  35. arrBought cart;
  36. int nItems;
  37. int count;
  38. struct Usertag *pNext;
  39. };
  40. typedef struct Usertag Usertype;
  41. typedef Usertype * ptrUser;
  42. typedef struct {
  43. Char supplier;
  44. Char product;
  45. int quantity;
  46. float puchase;
  47. float unit;
  48. float discount;
  49. int sold;
  50. Code code;
  51. }Productlist;
  52. typedef struct {
  53. Char category;
  54. Productlist list;
  55. }Addstock;
  56. void getUserinfo (Userinfo *uInfo){
  57. printf("Enter your First Name: ");
  58. fgets(uInfo->Userinfo.First ,MAXNAME,stdin);
  59. printf("Enter your Middle Name: ");
  60. fgets(uInfo->Userinfo.Second,MAXNAME,stdin);
  61. printf("Enter your Last Name: ");
  62. fgets(uInfo->Userinfo.Last,MAXNAME,stdin);
  63. printf("Enter your Address: ");
  64. fgets(uInfo->Address,MAXADD,stdin);
  65. uInfo->Userinfo.Last[strlen(uInfo->Userinfo.Last)-1]='\0';
  66. uInfo->Userinfo.First[strlen(uInfo->Userinfo.First)-1]='\0';
  67. uInfo->Userinfo.Second[strlen(uInfo->Userinfo.Second)-1]='\0';
  68. if (uInfo->Userinfo.First[0] >= 97 && uInfo->Userinfo.First[0] <=122)
  69. uInfo->Userinfo.First[0]-=32;
  70. if (uInfo->Userinfo.Second[0] >= 97 && uInfo->Userinfo.Second[0] <=122)
  71. uInfo->Userinfo.Second[0]-=32;
  72. if (uInfo->Userinfo.Last[0] >= 97 && uInfo->Userinfo.Last[0] <=122)
  73. uInfo->Userinfo.Last[0]-=32;
  74. printf("Your Name is: ");
  75. printf("%s, %s %s\n",uInfo->Userinfo.Last,uInfo->Userinfo.First,uInfo->Userinfo.Second);
  76. printf("Your Address is: ");
  77. printf("%s\n",uInfo->Address);
  78. }
  79. int passcheck (Usertype *user){
  80. int i,count=0;
  81. for (i=0;i<strlen(user->password);i++)
  82. if ((user->password[i] < 'A' || user->password[i] > 'Z'))
  83. if ((user->password[i] < 'a' || user->password[i] > 'z'))
  84. count++;
  85. if (count==0)
  86. printf("You must have at least 1 non-letter character\n");
  87. return count;
  88. }
  89. int length (Usertype *user){
  90. if (strlen (user->password) < 6){
  91.  
  92. printf("password is too short \n");
  93. return 0;
  94. }
  95.  
  96. else if (strlen (user->password) > 15){
  97. printf("password is too long \n");
  98. return 0;
  99. }
  100. else return 1;
  101. }
  102. void Signup (Usertype *user){
  103. char cDump;
  104. Adcd Admincode;
  105. do{
  106. printf("Enter Username: ");
  107. scanf("%s%c",user->username,&cDump);
  108. } while (strlen (user->username) < 3|| strlen(user->username) > 15);
  109. printf("%s\n",user->username);
  110.  
  111. do{
  112. printf("Enter Password: ");
  113. scanf("%s%c",user->password,&cDump);
  114. } while (length (user)==0 || passcheck(user)==0);
  115.  
  116. printf("%s\n",user->password);
  117.  
  118. getUserinfo (&user->info);
  119. printf("Enter account type [S]hopper or [A]dmin : ");
  120. scanf("%c",&user->type);
  121. if (user->type=='s'|| user->type=='S'){
  122. user->credlimit = 5000.00;
  123. user->outstanding = 0.00;
  124. user->nItems = 0;
  125. }
  126. else if (user->type == 'a' || user->type == 'A'){
  127. printf("Enter Admin Code: \n");
  128. do{
  129. scanf("%s",Admincode);
  130. if (strcmp(Admincode,"DLSU2017")==0)
  131. user->type = 'A';
  132. } while (strcmp(Admincode,"DLSU2017")!=0);
  133. }
  134. user->count=0;
  135. }
  136. int login (Usertype *user) {
  137. Char input;
  138. do {
  139. printf("Enter Username: ");
  140. scanf("%s",input);
  141. if (strcmp (user->username,input)==0 && user->count < 4){
  142. do{
  143. printf("Enter Password: ");
  144. scanf("%s",input);
  145. if (strcmp (user->password,input)!=0){
  146. printf("Try again, %d try/s left\n",3-user->count);
  147. user->count++;
  148. }
  149. } while (user->count <= 3 && strcmp (user->password,input) !=0);
  150. if (strcmp(user->password,input)==0)
  151. return 1;
  152. else if (user->count >= 3)
  153. return 0;
  154. }
  155.  
  156. } while (strcmp (user->username,input));
  157. return 0;
  158. }
  159. void Adminmenu (Usertype *user,int *esc){
  160. int exit=1,input;
  161. do {
  162. printf("ADMIN MENU \n");
  163. printf("Choose an option \n");
  164. printf("Manage Accounts: 1 \n");
  165. printf("Manage Stocks: 2 \n");
  166. printf("Prepare Delivery Report: 3 \n");
  167. printf("Shutdown Kioski: 4 \n");
  168. printf("Log out: 5 \n");
  169. scanf("%d",&input);
  170. switch (input) {
  171. // case 1: Manageaccounts (user);
  172. // case 2: Managestocks (user);
  173. // case 3: Deliveryreport (user);
  174. case 4: *esc = 0; break;
  175. case 5: exit = 0;
  176. }
  177. } while (exit);
  178. }
  179. void Changename (Userinfo *uInfo){
  180. printf("Enter your First Name: ");
  181. fgets(uInfo->Userinfo.First,MAXNAME,stdin);
  182. fgets(uInfo->Userinfo.First,MAXNAME,stdin);
  183. printf("Enter your Middle Name: ");
  184. fgets(uInfo->Userinfo.Second,MAXNAME,stdin);
  185. printf("Enter your Last Name: ");
  186. fgets(uInfo->Userinfo.Last,MAXNAME,stdin);
  187. uInfo->Userinfo.Last[strlen(uInfo->Userinfo.Last)-1]='\0';
  188. uInfo->Userinfo.First[strlen(uInfo->Userinfo.First)-1]='\0';
  189. uInfo->Userinfo.Second[strlen(uInfo->Userinfo.Second)-1]='\0';
  190. if (uInfo->Userinfo.First[0] >= 97 && uInfo->Userinfo.First[0] <=122)
  191. uInfo->Userinfo.First[0]-=32;
  192. if (uInfo->Userinfo.Second[0] >= 97 && uInfo->Userinfo.Second[0] <=122)
  193. uInfo->Userinfo.Second[0]-=32;
  194. if (uInfo->Userinfo.Last[0] >= 97 && uInfo->Userinfo.Last[0] <=122)
  195. uInfo->Userinfo.Last[0]-=32;
  196. printf("Your New Name is: ");
  197. printf("%s, %s %s\n",uInfo->Userinfo.Last,uInfo->Userinfo.First,uInfo->Userinfo.Second);
  198. }
  199. void Changeadd (Userinfo *uInfo) {
  200. printf("Enter your Address: ");
  201. fgets(uInfo->Address,MAXADD,stdin);
  202. fgets(uInfo->Address,MAXADD,stdin);
  203. printf("Your New Address is: ");
  204. printf("%s\n",uInfo->Address);
  205. }
  206. void Changepass (Usertype *user) {
  207. char cDump;
  208. do{
  209. printf("Enter Password: ");
  210. scanf("%s%c",user->password,&cDump);
  211. } while (length (user)==0 || passcheck(user)==0);
  212. printf("Your new password is: ");
  213. printf("%s\n", user->password);
  214. }
  215. void Modifyinfo (Usertype *user) {
  216. int exit = 1,input;
  217. do {
  218. printf("Modify User Menu \n");
  219. printf("Choose an option \n");
  220. printf("Change Name: 1 \n");
  221. printf("Change Address: 2 \n");
  222. printf("Change Password: 3 \n");
  223. printf("Return to Shopper Menu: 4 \n");
  224. scanf("%d",&input);
  225. switch (input) {
  226. case 1: Changename (&user->info); break;
  227. case 2: Changeadd (&user->info); break;
  228. case 3: Changepass (user); break;
  229. case 4: exit = 0;
  230. }
  231. } while (exit);
  232. }
  233. void Settlebalance (Usertype *user) {
  234. int card,security,paid=1;
  235. float payment;
  236. printf("Your outstanding balance is %.2f \n",user->outstanding);
  237. printf("Enter your credit card number (without spaces): ");
  238. scanf("%d",&card);
  239. printf("Enter your security code: ");
  240. scanf("%d",&security);
  241. do {
  242. printf("Enter amount: ");
  243. scanf("%f",&payment);
  244. if (payment <= user->outstanding){
  245. user->outstanding -= payment;
  246. paid=0;
  247. }
  248. else
  249. printf("You entered too much!");
  250. } while (paid);
  251. printf("Your new balance is %.2f\n",user->outstanding);
  252. }
  253. void Shoppermenu (Usertype *user){
  254. int exit = 1,input;
  255. do {
  256. printf("Shopper Menu \n");
  257. printf("Choose an option \n");
  258. printf("Modify User Info: 1 \n");
  259. printf("Browse All Products: 2 \n");
  260. printf("Browse Products by Category: 3 \n");
  261. printf("Browse Products on Sale: 4 \n");
  262. printf("Add to Cart: 5 \n");
  263. printf("View Cart: 6 \n");
  264. if (user->outstanding != 0.00)
  265. printf("Settle Outstanding Balance: 7 \n");
  266. printf("Log out: 8 \n");
  267. scanf ("%d",&input);
  268. switch (input) {
  269. case 1: Modifyinfo (user); break;
  270. case 2:
  271. case 3:
  272. case 4:
  273. case 5:
  274. case 6:
  275. case 7: Settlebalance (user); break;
  276. case 8: exit = 0;
  277. }
  278. } while (exit);
  279. }
  280. void displayAll (ptrUser pUser){
  281. while (pUser != NULL) {
  282. printf("%s\n",pUser->username);
  283. pUser=pUser->pNext;
  284. }
  285. }
  286. void freeAll (ptrUser *pUser) {
  287. ptrUser pTemp;
  288. while ((*pUser) != NULL){
  289. pTemp= *pUser;
  290. *pUser = (*pUser)->pNext;
  291. free(pTemp);
  292. }
  293. }
  294. int main () {
  295. int exit=1,input;
  296. Usertype user;
  297. ptrUser pUsers = NULL,
  298. pNew, pLast;
  299.  
  300. do {
  301. printf("Main Menu \n");
  302. printf("Choose an option: \n");
  303. printf("Log-in : 1\n");
  304. printf("Sign-up : 2\n");
  305. scanf("%d",&input);
  306. switch (input){
  307. case 1: if (login (&user)){
  308. if (user.type == 's' || user.type == 'S')
  309. Shoppermenu (&user);
  310. else if (user.type == 'A')
  311. Adminmenu (&user,&exit);
  312. } break;
  313. case 2: pNew = malloc(sizeof(Usertype));
  314. Signup (pNew);
  315. pNew->pNext = NULL ;
  316. if (pUsers == NULL)
  317. pUsers = pNew;
  318. else
  319. pLast->pNext = pNew;
  320. pLast=pNew;
  321. break;
  322. case 3: displayAll (pUsers); break;
  323. case 4: freeAll(&pUsers);
  324. }
  325. } while (exit);
  326.  
  327. return 0;
  328. }
Add Comment
Please, Sign In to add comment