Advertisement
Guest User

C++

a guest
Sep 29th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. /*
  2.  
  3. ##############################################
  4. Program name : Login Example
  5. Description : Login program for learners
  6. Author : Derek Brazil
  7. Date : 27/08/2016
  8. ##############################################
  9.  
  10. Before other programmers look at this and say ew.
  11. I used If statments as a loop because it was easlier to clarify.
  12.  
  13. */
  14.  
  15. #pragma region Includes
  16. #include "stdafx.h"
  17. #include <iostream>
  18. #include <string>
  19. #include <cstdlib>
  20. #include <cmath>
  21. #include <cstring>
  22. #include <Windows.h>
  23. using namespace std;
  24. #pragma endregion
  25.  
  26. #pragma region Functions
  27. template <typename T>
  28. void output(T shit) {
  29. cout << shit << endl;
  30. };
  31. void Restart()
  32. {
  33. cout << "\n" << endl;
  34.  
  35. string Userlist[5] = { "Martin", "Derek", "Caitlin", "Dean", "Sarah" };
  36.  
  37. string Passlist[5] = { "Martin123", "Derek123", "Caitlin123", "Dean123", "Sarah123" };
  38.  
  39. cout << "Below is a list of User's" << endl;
  40.  
  41. for (int i = 0; i < 5; i++)
  42. {
  43. cout << Userlist[i] << endl;
  44. }
  45.  
  46. cout << "\n" << endl;
  47.  
  48. string username;
  49.  
  50. string password;
  51.  
  52. cout << "Type your Username : ";
  53.  
  54. cin >> username;
  55.  
  56. cout << "Type your Password : ";
  57.  
  58. cin >> password;
  59. for (int i = 0; i <= sizeof(Userlist); i++) {
  60. if (Userlist[i] == username && Passlist[i] == password) {
  61. cout << "You have been logged in, max Int capacity is ";
  62. switch (i) {
  63. case 1:
  64. output(MAXINT);
  65. break;
  66. case 2:
  67. output(MAXBYTE);
  68. break;
  69. case 3:
  70. output(MAXCHAR);
  71. break;
  72. case 4:
  73. output(MAXLONG);
  74. break;
  75. case 5:
  76. output(MAXWORD);
  77. break;
  78. default:
  79. output("Error wrong username or password");
  80. }
  81. }
  82. }
  83. }
  84.  
  85. /*
  86. if (username == Userlist[1] & password == Passlist[1]) {
  87. cout << "You have been logged in" << endl; cout << "Max Int Capacity is : " << MAXINT << endl;
  88. }
  89. else if (username == Userlist[0] & password == Passlist[0]) {
  90. cout << "You have been logged in" << endl; cout << "Max Byte Capacity is : " << MAXBYTE << endl;
  91. }
  92. else if (username == Userlist[2] & password == Passlist[2]) {
  93. cout << "You have been logged in" << endl; cout << "Max Char Capacity is : " << MAXCHAR << endl;
  94. }
  95. else if (username == Userlist[3] & password == Passlist[3]) {
  96. cout << "You have been logged in" << endl; cout << "Max Long Capacity is : " << MAXLONG << endl;
  97. }
  98. else if (username == Userlist[4] & password == Passlist[4]) {
  99. cout << "You have been logged in" << endl; cout << "Max Word Capacity is : " << MAXDWORD << endl;
  100. }
  101. else {
  102. cout << "Error wrong username or password" << endl;
  103. }
  104.  
  105. }
  106. */
  107. void wrongInput()
  108. {
  109. cout << "Type \"Restart\" to try again : ";
  110.  
  111. string restart;
  112.  
  113. cin >> restart;
  114.  
  115. if (restart == "Restart")
  116. {
  117. Restart();
  118. }
  119. else
  120. {
  121. cout << "Input not valid!" << endl;
  122. }
  123. }
  124.  
  125. void Program() {
  126. cout << "Please login to get the max \"int\" value capacity" << endl;
  127.  
  128. string Userlist[5] = { "Martin", "Derek", "Caitlin", "Dean", "Sarah" };
  129.  
  130. string Passlist[5] = { "Martin123", "Derek123", "Caitlin123", "Dean123", "Sarah123" };
  131.  
  132. cout << "Below is a list of User's" << endl;
  133.  
  134. for (int i = 0; i < 5; i++)
  135. {
  136. cout << Userlist[i] << endl;
  137. }
  138.  
  139. string username;
  140.  
  141. string password;
  142.  
  143. cout << "Type your Username : ";
  144.  
  145. cin >> username;
  146.  
  147. cout << "Type your Password : ";
  148.  
  149. cin >> password;
  150.  
  151. if (username == Userlist[1] & password == Passlist[1]) {
  152. cout << "You have been logged in" << endl; cout << "Max Int Capacity is : " << MAXINT << endl;
  153. }
  154. else if (username == Userlist[0] & password == Passlist[0]) {
  155. cout << "You have been logged in" << endl; cout << "Max Byte Capacity is : " << MAXBYTE << endl;
  156. }
  157. else if (username == Userlist[2] & password == Passlist[2]) {
  158. cout << "You have been logged in" << endl; cout << "Max Char Capacity is : " << MAXCHAR << endl;
  159. }
  160. else if (username == Userlist[3] & password == Passlist[3]) {
  161. cout << "You have been logged in" << endl; cout << "Max Long Capacity is : " << MAXLONG << endl;
  162. }
  163. else if (username == Userlist[4] & password == Passlist[4]) {
  164. cout << "You have been logged in" << endl; cout << "Max Word Capacity is : " << MAXDWORD << endl;
  165. }
  166. else {
  167. cout << "Error wrong username or password" << endl;
  168.  
  169. cout << "Type \"Restart\" to try again : " << flush;
  170.  
  171. string restart;
  172.  
  173. cin >> restart;
  174.  
  175. if (restart == "Restart")
  176. {
  177. Restart();
  178. }
  179. else
  180. {
  181. cout << "Input not valid!" << endl;
  182. for (;;) {
  183. wrongInput();
  184. }
  185. }
  186. }
  187. }
  188. cout << "Thanks for using my program will restart in 5 seconds :)\n" << endl;
  189. Sleep(5000);
  190. #pragma endregion
  191.  
  192. #pragma region Main
  193. int main()
  194. {
  195. while(true){
  196. Program();
  197. }
  198. return 0;
  199. }
  200. #pragma endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement