Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. int main()
  2. {
  3. string name;
  4. int choice;
  5. int id = 0;
  6.  
  7. readFile();
  8.  
  9. // Log in validation
  10. while (id <= 0)
  11. {
  12. id = logIn();
  13. }
  14.  
  15. //name = "<Name>";
  16. name = userID[id].getFirstname();
  17. cout << "Welcome, " << name << "!\n";
  18.  
  19.  
  20. do{
  21. choice = mainMenu();
  22.  
  23. switch(choice)
  24. {
  25. case 1: // view friends
  26. viewFriends(id);
  27. break;
  28.  
  29. case 2: // search for new friends
  30. searchNewFriends();
  31. break;
  32.  
  33. case 3: // friends rec
  34. friendRecs();
  35. break;
  36.  
  37. case 4: // quit
  38. {
  39. cout << " You are signed out"
  40. << "\n\t- GOODBYE! -" << endl;
  41. }
  42. }
  43.  
  44. }while(choice != 4);
  45.  
  46. return 0;
  47. }
  48.  
  49. /// Returns bool for whether or not username & password combo are matched
  50. int logIn()
  51. {
  52. string un, pw, fn, ln, city, state;
  53. int choice = 0;
  54. int id;
  55. bool option = false;
  56.  
  57. while (!option)
  58. {
  59. while (choice != 1 && choice != 2 && choice != 3)
  60. {
  61. cout << "\t- WELCOME TO SPONGEBOOK -" << endl;
  62. cout << "1. Log in " << endl;
  63. cout << "2. Create an account " << endl;
  64. cout << "3. Quit " << endl;
  65. cout << "\nEnter choice: ";
  66. cin >> choice;
  67. cout << endl;
  68. }
  69.  
  70. if (choice == 1)
  71. {
  72. int count = 0;
  73.  
  74. while (true)
  75. {
  76. string userInput;
  77.  
  78. cout << "\t- LOG IN -" << endl
  79. << "Username: ";
  80. cin >> un;
  81. cout << "Password: ";
  82. cin >> pw;
  83.  
  84. for (int i = 1; i <= userID.size(); i++)
  85. {
  86. if (un == userID[i].getUsername() && pw == userID[i].getPassword())
  87. {
  88. cout << "\n\t*** Login successful ***\n" << endl;
  89. id = i;
  90. option = true;
  91. return id;
  92. }
  93. }
  94.  
  95. cout << "\n\t*** Incorrect username or password. Please try again **" << endl;
  96. count ++;
  97.  
  98. if (count > 3)
  99. {
  100. while (userInput != "YES" && userInput != "NO")
  101. {
  102. cout << "\nMultiple failed attempts. Would you like to go back to the main menu? ";
  103. cin >> userInput;
  104. transform(userInput.begin(), userInput.end(), userInput.begin(),::toupper);
  105. }
  106.  
  107. if (userInput == "YES")
  108. {
  109. cout << endl;
  110. choice = 0;
  111. option = true;
  112. return false;
  113. }
  114. else if (userInput == "NO")
  115. {
  116. choice = 1;
  117. count = 0;
  118. }
  119.  
  120. }
  121.  
  122. }
  123. }
  124. else if (choice == 2)
  125. {
  126. cout << "\t- CREATE AN ACCOUNT -" << endl
  127. << "First name: ";
  128. cin >> fn;
  129.  
  130. cout << "Last name: ";
  131. cin >> ln;
  132.  
  133. cout << "Username: ";
  134. cin >> un;
  135.  
  136. cout << "Password: ";
  137. cin >> pw;
  138.  
  139. cout << "City: ";
  140. cin.ignore();
  141. getline(cin, city);
  142.  
  143. cout << "State: ";
  144. cin >> ws;
  145. cin >> state;
  146.  
  147. id = userID.size() + 1;
  148.  
  149. User newUser(fn, ln, un, pw, city, state, id);
  150. userID.push_back(newUser);
  151.  
  152. cout << "\n\t*** Account successfully created. You may now log in ***\n" << endl;
  153. choice = 0;
  154. }
  155. else if (choice == 3)
  156. {
  157. cout << "\t- GOODBYE! -" << endl;
  158. exit(0);
  159. }
  160. }
  161. return id;
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement