Guest User

Untitled

a guest
Mar 2nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9. int sum(int a, int b)
  10. {
  11. int c;
  12. c = a + b;
  13. return c;
  14. }
  15.  
  16. bool isNumber(char Symbol)
  17. {
  18. if (Symbol >= '0' && Symbol <= '9')
  19. return true;
  20. return false;
  21. }
  22.  
  23. void registration(string name1, string pass1, bool IsRegistered)
  24. {
  25. cout << "Your username: ";
  26. cin >> name1;
  27. cout << "Your password: ";
  28. cin >> pass1;
  29. ofstream fout;
  30. fout.open(name1);
  31. fout << "Username = " << name1 << endl;
  32. fout << "Password = " << pass1 << endl;
  33. cout << "Great! You've signed up! Now come check your math calculation skills!" << endl;
  34. cout << "If you wish to leave the game, type in F" << endl;
  35. IsRegistered = true;
  36. }
  37.  
  38. void check(int a, int b, int c, int v, int solved, string name1)
  39. {
  40. c = sum(a, b);
  41. if (c == v)
  42. {
  43. cout << "Your answer is correct";
  44. cout << endl;
  45. solved++;
  46. }
  47. else
  48. {
  49. cout << "Your answer is incorrect";
  50. cout << endl;
  51. }
  52. }
  53.  
  54. void output(int a, int b, int c, int v, int solved, string name1)
  55. {
  56. srand((unsigned)time(NULL));
  57. a = 1 + rand() % 1000;
  58. b = 1 + rand() % 1000;
  59. heh:
  60. cout << "Solve it - " << a << " + " << b << endl;
  61. cout << "Your answer: ";
  62. cin >> v;
  63.  
  64. if (v > 9999)
  65. {
  66. cout << "Sorry, your number cannot be so big." << endl;
  67. goto heh;
  68. }
  69. else
  70. {
  71. check(a, b, c, v, solved,name1);
  72. output(a, b, c, v, solved, name1);
  73. }
  74. }
  75.  
  76. int main()
  77. {
  78. //bool correct = false;
  79. srand((unsigned)time(NULL));
  80. int v = 0;
  81. int a = 0;
  82. int b = 0;
  83. int c = 0;
  84. int solved = 0;
  85. string name1, pass1;
  86. bool IsRegistered = false;
  87.  
  88. registration(name1, pass1, IsRegistered);
  89. output(a, b, c, v, solved, name1);
  90. system("pause");
  91. }
Add Comment
Please, Sign In to add comment