-1

How to make like this? I want to try to make it. For example, I have an input whose contents must be odd

input = n > 0; 
n = odd numbers;

such as N = 1, then I want the result like this

        o              
o       x       o      
        o            

and if n is 3, will be like this

                o              
        o       x       o      
o       x       x       x       o
        o       x       o      
                o             

and so on. I want to try to make it, but always fail. This is the code I have:

#include <bits/stdc++.h>
using namespace std;

int main()
{
  int n;
  cin >> n;
  int x = n;
  n += 2;
  
  for (int i=0;i<n;i++) {
    for (int j=0;j<n;j++) {
      if (i == x-1 || j == x-1) {
        cout << "x";
      } else {
        cout << "o";
      }
    }
    cout << endl;
  }
}
halfer
  • 19,471
  • 17
  • 87
  • 173
Soel
  • 33
  • 1
  • 4
  • 1
    One of the reasons is that you didn't even output the blanks(spaces), so all of them will be crammed to the left – HenryLu May 12 '22 at 03:38
  • @HenryLu where should i put the space? can you give an example? – Soel May 12 '22 at 03:42
  • 1
    ... on the left. Have a look at your loop. See the part you output a newline? That's on the _right_. So, where do you think you should be outputting spaces to indent the left side? – paddy May 12 '22 at 03:48
  • 1
    [Why should I not `#include `?](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) [Why is `using namespace std;` considered bad practice?](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) – Evg May 12 '22 at 06:07
  • 3
    `#include ` -- This is probably the result of trying to learn C++ from garbage websites instead of learning C++ from good books. – PaulMcKenzie May 12 '22 at 06:24

0 Answers0