‘o’ is uninitialized, hence after this line x=o;
x is assigned an unspecified value.
Therefore this loop:
1 2 3
for(int n=0;n<x;n++){
std::cout<<" ";
}
might iterate millions of times and millions of std::couts may take a while.
Just sit down and wait: I think it’s a proper punishment for having written that code.
- just kidding ;-)
I was trying to print the left border of a hexagon with the char inputed.
Thank you for having kept that secret: it would have been very stressful for us to get a description of your code before reading it.
But o gets initialized in every loop so it should not matter, or does it?
Is o initialized before being assigned to ‘x’?
By the way, may I suggest you to change your variable name from lowercase ‘o’ to uppercase ‘O’?
It would be far funnier to tell apart these two instructions:
I am taking a guess that a positive number will draw the upper part of a hexagon, and a negative number will draw the lower part of a hexagon. I added the text "Number of Columns: " and "Character: " to help make it clearer for the user to understand the input.
Entering the number 5 with a character T will show the following output
T
T
T
T
T
Entering the number -5 with a character G will show the following output
G
G
G
G
G
Yes, the variable o will need to be initialized with a number for it to be valid. I limited modifications to your code and here is working code that I have. A variable called Startx was also added which contained the inverse of the original value so that spacing can start at zero and progress to a higher number for the lower-half of the hexagon.
Yes!! Thankyou very much @eugenedakin. Actually your idea with the variable Startx is very nice.
My code wasn't working also when I implemented that.
The I have changed cin>>x>>c; to cin>>x;cin>>c; and it worked. Why did that happen?!
Now it works..