Hello! I apologize if I'm breaking any unspoken or spoken forum rules. I'm completely new to C++ and the forum scene in general. I would appreciate any assistance or direction that anyone can offer :)
The Problem:
Program Language: C++
Using: Visual studio 2010
Alright, So I am doing an exercise with loops given to me by my professor.
Basically, I am having trouble getting this little pattern to appear in my output display.
Ideally it looks like this.
*
.. *
.... *
......*
NOTE: Without the periods, I only did that because the forum messenger takes away any empty spaces.
Easy enough right? Well, They need to be individually placed. Now, every time they go through the loop, I need to Add two spaces to the next one. The trouble is I have no idea how to add those two spaces automatically using a loop. I know that this is insanely simple and the solution is probably staring me right in the face but I just can't see it. Any help is enormously appreciated!
So basically, I needs to create a "for" loop that will initially place one asterisk, go through the loop again, enter two spaces, enter the asterisk, go through the loop again, etc.
I can use any many if statements, loops, etc as a like though. I'm sorry I know I'm not the most well spoken guy in the world, far from it.
Yes. Try to use code tags on posts. It makes reading and commenting easier.
Do notice that you don't need separate 'loopcounter', because you have the 'i'. Actually, we really like the i's 0..N-1 values rather than the loopcounters 1..N range. Lets rename the 'i' to 'row' to be more expressive.
#include <iostream>
int main()
{
using std::cout;
using std::cin;
using std::endl;
int row, N;
cout << "Enter N" << endl;
cin >> N;
cout << endl << endl;
for ( row=0; row < N; ++row )
{
cout << row << endl;
cout << "*\n";
}
return 0;
}
The line 16 prints a number. How many spaces should there be before the *? Do you notice any correlation between the 'row' value and the number of required spaces?
For the first * there should be no preceding spaces.
There should be 2 preceding spaces for the second *, on the second row.
There should be 4 preceding spaces for the third *, on the third row.
And I need that trend to continue throughout the program.
" Do you notice any correlation between the 'row' value and the number of required spaces?"
Yes, It would seem that for every 1 row I output after the first, I need to add two spaces.
What I mean to say is they go hand in hand and advance at the same pace.
Maybe I'm not understanding what you're saying.
I'll try the code tags the next time I post code, I'm brand spanking new, thanks for the advice!!