Advertisement
Guest User

Untitled

a guest
Aug 11th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctype.h>
  3. #include <cmath>
  4. #include <fstream>
  5. #include <string>
  6. using namespace std;
  7.  
  8. void login();
  9. void signup();
  10. int prompt();
  11. int filter(char command[]);
  12.  
  13. int main()
  14. {
  15. switch ( prompt() )
  16. {
  17. case 1:
  18. login();
  19. break;
  20. case 2:
  21. signup();
  22. break;
  23. }
  24. }
  25. int prompt()
  26. {
  27. char command[12];
  28. cout << " _________________________________ " << endl;
  29. cout << "| |" << endl;
  30. cout << "| Welcome to our game! |" << endl;
  31. cout << "| ---------------------- |" << endl;
  32. cout << "| What would you like to do? |" << endl;
  33. cout << "| ---------------------- |" << endl;
  34. cout << "|_________________________________|" << endl;
  35. cout << endl;
  36.  
  37. while (true)
  38. {
  39. cout << ">> ";
  40. cin >> command;
  41. cin.ignore(100, '\n');
  42. cout << endl;
  43.  
  44. if (filter(command) == 0)
  45. {
  46. cout << "\nERROR: Command wasn't recognized. Try again?" << endl;
  47. continue;
  48. }
  49. else
  50. break;
  51. }
  52. return filter(command);
  53. }
  54. int filter(char command[])
  55. {
  56. if ( _stricmp("play",command) == 0 || _stricmp("start",command) == 0 || _stricmp("login",command) == 0)
  57. return 1;
  58. else if ( _stricmp("new",command) == 0 || _stricmp("create",command) == 0 || _stricmp("make",command) == 0 )
  59. return 2;
  60. else
  61. return 0;
  62. }
  63. void login()
  64. {
  65. // ...
  66. }
  67. void signup()
  68. {
  69. ofstream loginData("data.txt", ios::app);
  70. if (loginData.fail())
  71. {
  72. cout << "ERROR: Login data was not found." << endl;
  73. exit(-1);
  74. }
  75. string username, password;
  76.  
  77. cout << "Desired Username: ";
  78. getline(cin, username);
  79.  
  80. cout << "Desired Password: ";
  81. getline(cin, password);
  82.  
  83. loginData << username << endl;
  84. loginData << password << endl;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement