Advertisement
TheLegend12

Untitled

Sep 21st, 2023
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. float a;
  10. float b;
  11. float c;
  12. float d;
  13. float res1;
  14. float res2;
  15. float res3;
  16. int operator1;
  17. int operator2;
  18. int operator3;
  19. string str1;
  20. string str2;
  21. string str3;
  22. int counter = 0;
  23. int startValue;
  24. int endValue;
  25. string userOperator1;
  26. string userOperator2;
  27. string userOperator3;
  28. srand(time(nullptr));
  29. string userOperators;
  30. int puzzleChosen = rand() % 3185 + 1;
  31. bool isEnterPressed = false;
  32.  
  33. cout << "Enter the beginning solution to be printed:";
  34. cin >> startValue;
  35. cout << endl;
  36. cout << "Enter the end solution to be printed: ";
  37. cin >> endValue;
  38. cout << endl;
  39.  
  40. for (a = 1; a <= 9; ++a)
  41. {
  42. for (b = 1; b <= 9; ++b)
  43. {
  44. for (c = 1; c <= 9; ++c)
  45. {
  46. for (d = 1; d <= 9; ++d)
  47. {
  48. for (operator1 = 1; operator1 <= 4; ++operator1)
  49. {
  50. for (operator2 = 1; operator2 <= 4; ++operator2)
  51. {
  52. for (operator3 = 1; operator3 <= 4; ++operator3)
  53. {
  54. if (operator1 == 1)
  55. {
  56. str1 = '+';
  57. res1 = a + b;
  58. }
  59. else if (operator1 == 2)
  60. {
  61. str1 = '-';
  62. res1 = a - b;
  63. }
  64. else if (operator1 == 3)
  65. {
  66. str1 = '/';
  67. res1 = a / b;
  68. }
  69. else if (operator1 == 4)
  70. {
  71. str1 = '*';
  72. res1 = a * b;
  73. }
  74.  
  75. if (operator2 == 1)
  76. {
  77. str2 = '+';
  78. res2 = res1 + c;
  79. }
  80. else if (operator2 == 2)
  81. {
  82. str2 = '-';
  83. res2 = res1 - c;
  84. }
  85. else if (operator2 == 3)
  86. {
  87. str2 = '/';
  88. res2 = res1 / c;
  89. }
  90. else if (operator2 == 4)
  91. {
  92. str2 = '*';
  93. res2 = res1 * c;
  94. }
  95. if (operator3 == 1)
  96. {
  97. str3 = '+';
  98. res3 = res2 + d;
  99. }
  100. else if (operator3 == 2)
  101. {
  102. str3 = '-';
  103. res3 = res2 - d;
  104. }
  105. else if (operator3 == 3)
  106. {
  107. str3 = '/';
  108. res3 = res2 / d;
  109. }
  110. else if (operator3 == 4)
  111. {
  112. str3 = '*';
  113. res3 = res2 * d;
  114. }
  115. if (res3 == 24)
  116. {
  117. ++counter;
  118. while
  119. if (counter >= startValue && counter <= endValue)
  120. {
  121. cout << counter << ":" << a << " " << str1 << " " << b << " " << str2 << " " << c << " " << str3 << " " << d;
  122. cout << " = " << res3;
  123. cout << endl;
  124. }
  125. if (counter == puzzleChosen)
  126. {
  127. cout << "Puzzle chosen is #" << counter << ":" << a << " " << str1 << " " << b << " " << str2 << " " << c << " " << str3 << " " << d;
  128. cout << endl;
  129. cout << "The numbers to use are " << a << " " << b << " " << c << " " << d;
  130. cout << endl;
  131. cout << "Enter the three operators to be used (+, -, * or / ):" << endl;
  132. cin >> userOperator1;
  133. cin >> userOperator2;
  134. cin >> userOperator3;
  135. userOperators = userOperator1 + userOperator2 + userOperator3;
  136. cout << endl;
  137. if (str1 == userOperator1 && str2 == userOperator2 && str3 == userOperator3 && userOperators.size() == 3)
  138. {
  139. cout << a << userOperator1 << b << " = " << res1 << endl;
  140. cout << res1 << userOperator2 << c << " = " << res2 << endl;
  141. cout << res2 << userOperator3 << d << " = " << res3 << endl;
  142. cout << "Well done!" << endl;
  143. }
  144.  
  145. else if(userOperators.size() != 3){
  146. cout << endl;
  147. cout << "invalid number of characters entered, please try again";
  148. cout << endl;
  149. }
  150. }
  151.  
  152. }
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
  160. return 0;
  161. }
  162.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement