Advertisement
luciapineda

signup Lucia fml

Mar 11th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. void signUp(userType *pUser){
  2. userType *pCurrent;
  3. string15 temp;
  4. int newUser=1;
  5. char cDump;
  6. int check, i;
  7. string8 authorization;
  8.  
  9.  
  10. printf("\n------SIGN UP------\n");
  11. do{
  12. newUser=1;
  13. printf("Enter username (3-15 characters): ");
  14. scanf("%s%c", temp, &cDump);
  15.  
  16. pCurrent=pUser;
  17. while(pCurrent!=NULL){
  18. if(strcmp(temp, pCurrent->username)==0)
  19. newUser=0;
  20. pCurrent=pCurrent->pNext;
  21. }
  22. if(newUser==1)
  23. strcpy(pUser->username, temp);
  24. else
  25. printf("Username already exists.\n");
  26.  
  27. } while(strlen(pUser->username)<3 || strlen(pUser->username)>15 || newUser==0);
  28.  
  29. do{
  30. printf("Enter password (6-15 characters, at least one must not be a letter): ");
  31. scanf("%s", pUser->password);
  32. for(i=0; i<strlen(pUser->password); i++){
  33. if(!(pUser->password[i]>='a' && pUser->password[i]<='z'|| pUser->password[i]>='a' && pUser->password[i]<='z'))
  34. check=1;
  35. }
  36. } while(check==0|| strlen(pUser->password)<6 || strlen(pUser->password)>15);
  37. getUserInfo(&pUser->info);
  38.  
  39. do{
  40. printf("Account type ([S]hopper or [A]dministrator): ");
  41. scanf("%c%c", &pUser->type, &cDump);
  42. if(!(pUser->type=='s' || pUser->type=='S' || pUser->type=='a' || pUser->type=='A'))
  43. printf("Invalid input.\n");
  44. } while(!(pUser->type=='s' || pUser->type=='S' || pUser->type=='a' || pUser->type=='A'));
  45.  
  46. if(pUser->type == 's' || pUser->type == 'S'){
  47. //shopper account is created
  48. pUser->creditlimit=5000.00;
  49. pUser->outstanding=0.00;
  50. pUser->nItems=0;
  51. printf("SHOPPER ACCOUNT CREATED.\n\n");
  52. }
  53. else if(pUser->type == 'a' || pUser->type == 'A'){
  54. //administrator account is created
  55. do{printf("Enter authorization code: ");
  56. scanf("%s", authorization);
  57.  
  58. if(strcmp(authorization,"DLSU2017")==0)
  59. printf("ADMINISTRATOR ACCOUNT CREATED.\n\n");
  60. else
  61. printf("Invalid authorization code.\n");
  62.  
  63. }while(strcmp(authorization,"DLSU2017")!=0);
  64.  
  65. }
  66. /*check:
  67. printf("[USER INFO]\n");
  68. printf("Username: %s\n", pUser->username);
  69. printf("Password: %s\n", pUser->password);
  70. }
  71.  
  72. int main(){
  73. ptrUser pUsers=NULL,
  74. pNew=NULL,
  75. pLast=NULL,
  76. pRun=NULL,
  77. pTrail=NULL;
  78. int opt,
  79. choose,
  80. accountCount=0;
  81. char cDump;
  82.  
  83. do{
  84. printf("------[MAIN MENU]------\n");
  85. printf("1 - Log In\n");
  86. printf("2 - Sign Up\n");
  87. printf("3 - Exit\n\n");
  88. printf("Choose option: ");
  89. scanf("%d", &choose);
  90.  
  91. if(choose==2){
  92. do{
  93. pNew=malloc(sizeof(userType));
  94. pNew->pNext=NULL;
  95. signUp(pNew);
  96.  
  97. if(pUsers==NULL) //list is empty
  98. pUsers=pNew;
  99. else if(strcmp(pUsers->username, pNew->username)>0){ //connect at first node
  100. pNew->pNext=pUsers;
  101. pUsers=pNew;
  102. }
  103. else{ //modifying middle of the list
  104. pRun=pUsers;
  105. while(pRun != NULL && strcmp(pRun->username, pNew->username)<0){
  106. pTrail=pRun;
  107. pRun=pRun->pNext;
  108. }
  109. pTrail->pNext=pNew;
  110. pNew->pNext=pRun;
  111. }
  112.  
  113.  
  114. accountCount++;
  115. printf("Another user? (1 for yes, 0 for no): ");
  116. scanf("%d%c", &opt, &cDump);
  117. }while(opt==1);
  118. }
  119.  
  120. if(choose==1)
  121. logIn(pUsers, accountCount);
  122.  
  123. if(choose==3)
  124. opt=1;
  125. }while(opt==0);
  126.  
  127. displayAll(pUsers);
  128. freeAll(&pUsers);
  129. // deleteNode(&pUsers, "cho");
  130.  
  131. return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement