Advertisement
Guest User

KILL ME

a guest
Mar 2nd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 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 {
  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. }Usertype;
  38. void getUserinfo (Userinfo *uInfo){
  39. printf("Enter your First Name: ");
  40. fgets(uInfo->Userinfo.First ,MAXNAME,stdin);
  41. printf("Enter your Middle Name: ");
  42. fgets(uInfo->Userinfo.Second,MAXNAME,stdin);
  43. printf("Enter your Last Name: ");
  44. fgets(uInfo->Userinfo.Last,MAXNAME,stdin);
  45. printf("Enter your Address: ");
  46. fgets(uInfo->Address,MAXADD,stdin);
  47. uInfo->Userinfo.Last[strlen(uInfo->Userinfo.Last)-1]='\0';
  48. uInfo->Userinfo.First[strlen(uInfo->Userinfo.First)-1]='\0';
  49. uInfo->Userinfo.Second[strlen(uInfo->Userinfo.Second)-1]='\0';
  50. if (uInfo->Userinfo.First[0] >= 97 && uInfo->Userinfo.First[0] <=122)
  51. uInfo->Userinfo.First[0]-=32;
  52. if (uInfo->Userinfo.Second[0] >= 97 && uInfo->Userinfo.Second[0] <=122)
  53. uInfo->Userinfo.Second[0]-=32;
  54. if (uInfo->Userinfo.Last[0] >= 97 && uInfo->Userinfo.Last[0] <=122)
  55. uInfo->Userinfo.Last[0]-=32;
  56. printf("Your Name is: ");
  57. printf("%s, %s %s\n",uInfo->Userinfo.Last,uInfo->Userinfo.First,uInfo->Userinfo.Second);
  58. printf("Your Address is: ");
  59. printf("%s\n",uInfo->Address);
  60. }
  61. void Signup (Usertype *user){
  62. char cDump;
  63. Adcd Admincode;
  64. do{
  65. printf("Enter Username: ");
  66. scanf("%s%c",user->username,&cDump);
  67. } while (strlen (user->username) < 3|| strlen(user->username) > 15);
  68. printf("%s\n",user->username);
  69.  
  70. do{
  71. printf("Enter Password: ");
  72. scanf("%s%c",user->password,&cDump);
  73. } while (strlen (user->password) < 6|| strlen(user->password) > 15);
  74. printf("%s\n",user->password);
  75.  
  76. getUserinfo (&user->info);
  77. printf("Enter account type: ");
  78. scanf("%c",&user->type);
  79. if (user->type=='s'|| user->type=='S'){
  80. user->credlimit = 5000.00;
  81. user->outstanding = 0.00;
  82. user->nItems = 0;
  83. }
  84. else if (user->type == 'a' || user->type == 'A'){
  85. printf("Enter Admin Code: \n");
  86. do{
  87. scanf("%s",&Admincode);
  88. if (strcmp(Admincode,"DLSZU2017")==0)
  89. user->type = 'A';
  90. } while (strcmp(Admincode,"DLSZU2017")!=0);
  91. }
  92. int main () {
  93. int exit=1,input;
  94. Usertype user;
  95. do {
  96. printf("Choose an option: \n");
  97. printf("Log-in : 1\n");
  98. printf("Sign-up : 2\n");
  99. printf("Exit : 3\n");
  100. scanf("%d",&input);
  101. switch (input){
  102. case 1:
  103. case 2: Signup (&user); break;
  104. case 3: printf("Exiting program\n"); exit=0; break;
  105. }
  106. } while (exit);
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement