``````cout << "Gradual increase:\n";
for (int a=1; a <= 5; a++) {
for (int b=0; b <= a; b++)
cout << b;
cout << endl;
}
cin.get ();
}``````

Shows up as :
01
012
0123
01234
012345
I've been asking my friend, and his given me a couple of hints, on how to shorten the program and stablize the rest of it. But this program didnt work out, i cant figure out what exactly i did wrong... Don't answer it for me, just tell or show me the line i messed up on, and ill figure it out form there, wanna work my brain so i emorize how to do all of this.

>show me the line i messed up on
This one:

``for (int b=0; b <= a; b++)``

Thankyou, tried taking 0 and putting in 1, but it was so late last night, and i didnt press compile i guess, but now that part works, and the next drawing will be a peice of cake.

``````for (int a=1; a>=5; a--) {
for (int b=1; b<=a; b++)``````

Wich one of these two lines is incorect, i've tried switching things around many times, nothing's worked so far, each time just gives me a bunch of blank space..

>for (int a=1; a>=5; a--) {
Is 1 greater than or equal to 5?

No, lol, got it thx, didnt even read it that hard to see it. now comes the pyrimid, and i have NO idea on how to do it. Maybe you can gimme an algorithm of it, and ill translate it into code.

Narue, maybe just a hint then? cuz ive tried some things, unlucky so far.

>Narue, maybe just a hint then?
Instead of one loop inside of a loop, use two loops inside of a loop. The outer loop handles rows, the first inner loop handles spaces, and the second inner loop handles the numbers:

``````for each row
for each space
print a space
for each number
print a number``````

The trick is in working out how many spaces to print and how many numbers to print in relation to the row. Start by drawing this:

``````*
**
***
****
*****``````

Then work out the math required to print another n - 1 fill characters after the center line. That way you break the problem into two steps that are easier to solve than the entire problem all at once.

``````cout << "**********" << endl;
cout << "Pyrimid:\n";
for (int a=5; a>0; a--) {
for (int b=0; b<9; b++)
cout << " ";
cout << "\n";
for (int c=9; c>0; c--)
cout << c;
cout << "\n";
}
cin.get ();
}``````

This shows up as:

987654321

987654321

987654321

987654321

987654321

How do i get it to do the pyrimid? lol, ive tried several things.

>How do i get it to do the pyrimid?
You're going to smack yourself when you see the solution that I was pushing you for:

``````#include <iostream>

using std::cout;
using std::endl;
using std::cin;

int main()
{
int h;

cout<<"Enter the height of your new pyramid: ";
if ( cin>> h ) {
for ( int i = 0; i < h; i++ ) {
for ( int j = 0; j < h - 1 - i; j++ )
cout<<' ';
for ( int j = 0; j < i * 2 + 1; j++ )
cout<<'*';
cout<<endl;
}
}
}``````

It takes only three minor changes to print digits starting at 1, though you can only print up to a height of 5 before double digit numbers mess up the formatting.

``````#include <iostream>

using std::cout;
using std::endl;
using std::cin;

int main()
{
cout << "Full box:\n";
for ( int a=0; a<5; a++ ) {
for ( int b=5; b>0; b-- ) {
cout<< b;
}
cout << endl;
}
cout << "**********" << endl;
cout << "Empty box:\n";
for (int a=5;a>0; a--) {
for (int b=5; b > 0; b-- )
if ( ((a > 1) && (a < 5)) && (b > 1) && (b < 5))
cout << " ";
else cout << b;
cout << "\n";
}
cout << "**********" << endl;
for (int a=1; a<=5; a++) {
for (int b=1; b<=a; b++)
cout << b;
cout << endl;
}
cout << "**********" << endl;
for (int a=5; a>=1; a--) {
for (int b=1; b<=a; b++)
cout << b;
cout << endl;
}
cout << "**********" << endl;
cout << "Pyrimid:\n";
for (int a=0;a<5;a++) {
for (int b=1;b<10;b++)
if ( (b<(5-a)) || (b>(5+a)) )
cout << " ";
else cout << b;
cout << endl;
}
cin.get ();
}``````

There it is finished, all done.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.