Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- float a;
- float b;
- float c;
- float d;
- float res1;
- float res2;
- float res3;
- int operator1;
- int operator2;
- int operator3;
- char str1;
- char str2;
- char str3;
- char str4;
- int counter = 0;
- int startValue;
- int endValue;
- char userOperator1;
- char userOperator2;
- char userOperator3;
- srand(time(nullptr));
- int puzzleChosen = rand() % 3185 + 1;
- cout << "Enter the beginning solution to be printed:";
- cin >> startValue;
- cout << endl;
- cout << "Enter the end solution to be printed: ";
- cin >> endValue;
- cout << endl;
- for (a = 1; a <= 9; ++a)
- {
- for (b = 1; b <= 9; ++b)
- {
- for (c = 1; c <= 9; ++c)
- {
- for (d = 1; d <= 9; ++d)
- {
- for (operator1 = 1; operator1 <= 4; ++operator1)
- {
- for (operator2 = 1; operator2 <= 4; ++operator2)
- {
- for (operator3 = 1; operator3 <= 4; ++operator3)
- {
- if (operator1 == 1)
- {
- str1 = '+';
- res1 = a + b;
- }
- else if (operator1 == 2)
- {
- str1 = '-';
- res1 = a - b;
- }
- else if (operator1 == 3)
- {
- str1 = '/';
- res1 = a / b;
- }
- else if (operator1 == 4)
- {
- str1 = '*';
- res1 = a * b;
- }
- if (operator2 == 1)
- {
- str2 = '+';
- res2 = res1 + c;
- }
- else if (operator2 == 2)
- {
- str2 = '-';
- res2 = res1 - c;
- }
- else if (operator2 == 3)
- {
- str2 = '/';
- res2 = res1 / c;
- }
- else if (operator2 == 4)
- {
- str2 = '*';
- res2 = res1 * c;
- }
- if (operator3 == 1)
- {
- str3 = '+';
- res3 = res2 + d;
- }
- else if (operator3 == 2)
- {
- str3 = '-';
- res3 = res2 - d;
- }
- else if (operator3 == 3)
- {
- str3 = '/';
- res3 = res2 / d;
- }
- else if (operator3 == 4)
- {
- str3 = '*';
- res3 = res2 * d;
- }
- if (res3 == 24)
- {
- ++counter;
- if (counter >= startValue && counter <= endValue)
- {
- cout << counter << ":" << a << " " << str1 << " " << b << " " << str2 << " " << c << " " << str3 << " " << d;
- cout << " = " << res3;
- cout << endl;
- }
- if (counter == puzzleChosen)
- {
- cout << "Puzzle chosen is #" << counter << ":" << a << " " << str1 << " " << b << " " << str2 << " " << c << " " << str3 << " " << d;
- cout << endl;
- cout << "The numbers to use are " << a << " " << b << " " << c << " " << d;
- cout << endl;
- cout << "Enter the three operators to be used (+, -, * or / ):" << endl;
- cin >> userOperator1;
- cin >> userOperator2;
- cin >> userOperator3;
- cout << endl;
- if (str1 == userOperator1 && str2 == userOperator2 && str3 == userOperator3)
- {
- cout << a << userOperator1 << b << " = " << res1 << endl;
- cout << res1 << userOperator2 << c << " = " << res2 << endl;
- cout << res2 << userOperator3 << d << " = " << res3 << endl;
- cout << "Well done!" << endl;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement