My professor and TA are not good teachers, whatsoever... I tried to ask them about the logic of looping, but they won't give me an answer. Instead, they keep beating around the bush, and I am even more confused than when I started. I understand the logic behind looping, it's more in the lines of making pictures with my loops is my problem.
For example:
We have to write a program that's a pyramid using numbers that are odd based on the input of the user.
so if the user inputs "13" it should look something like this:
7
876
98765
0987654
109876543
21098765432
3210987654321
|
I know this program requires one outer loop, and two inner loops. But I don't understand the logic of setting the loops up, that's where I'm stuck. I failed my midterm because of this.
Here's what I have for the for loop right now:
Input: for(int i=1; i<=numRows; i++)
{
for(int j=1; j<=i; j++)
{
cout << " ";
}
for (int j=1; j<=i; j++)
{
cout << numRows/2+1;
}
i++;
cout <<endl;
}
|
Note: the input i used was 13.
Output:
7
777
77777
7777777
777777777
77777777777
7777777777777
|
It's not what I need, but I'm getting somewhere. I know this program requires the "%" somewhere, and there are too many spaces between each line as well.
What would be a good way to think about loops. I have to start at a certain number for the first one which is numRows/2+1, and when I go down a row, I gain two numbers and lose one space.
Any and all help would be appreciated.
Thank you.