Advertisement
avr39ripe

cppTriangleMadnessNew

Jul 1st, 2021
1,447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. const int size{ 9 };
  4. int a, b, c, d;
  5. char input{ 'x' };
  6. bool positive{ false };
  7. const char pos{ '*' };
  8. const char neg{ ' ' };
  9.  
  10. int main()
  11. {
  12.     do
  13.     {
  14.         std::cout << "Enter figure a, b, c, d, e, f, g, h, i, j or x to exit\n";
  15.         std::cin >> input;
  16.         if (input == 'a') { a = -1; b = 1; c = 1; d = 1; }
  17.         else if (input == 'b') { a = -1; b = -1; c = 1; d = -1; }
  18.         else if (input == 'c') { a = -1; b = 1; c = -1; d = 1; }
  19.         else if (input == 'd') { a = 1; b = -1; c = 1; d = -1; }
  20.         else if (input == 'e') { a = -1; b = 1; c = 1; d = -1; }
  21.         else if (input == 'f') { a = -1; b = -1; c = 1; d = 1; }
  22.         else if (input == 'g') { a = -1; b = -1; c = -1; d = -1; }
  23.         else if (input == 'h') { a = 1; b = 1; c = 1; d = 1; }
  24.         else if (input == 'i') { a = -1; b = -1; c = -1; d = 1; }
  25.         else if (input == 'j') { a = 1; b = -1; c = 1; d = 1; }
  26.         else if (input == 'x') { break; }
  27.         else { std::cout << "Incorrect input\n"; continue; };
  28.         for (int y{ 0 }; y < size; ++y)
  29.         {
  30.             for (int x{ 0 }; x < size; ++x)
  31.             {
  32.                 positive = (a * (x + y) >= a * (size - 1) and b * x >= b * y) or (c * (x + y) >= c * (size - 1) and d * x >= d * y);
  33.                 std::cout << ' ' << (positive ? pos : neg) << ' ';
  34.             }
  35.             std::cout << '\n';
  36.         }
  37.         std::cout << '\n';
  38.     } while (input != 'x');
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement