Advertisement
TheLegend12

Untitled

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