Advertisement
TheLegend12

Untitled

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