Advertisement
TheLegend12

Untitled

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