a slightly different triangle
I've looked through many old posts and have not seen one like this. I know creating a triangular shape composed of *'s is common, but this one's a little different.
This is how the output should look:
1
12
123
1234
123
12
1
I have tried to write some code, but I substituted *'s for numbers to see if I could get that to work first. As usual, it's not working. Could anyone give me some idea where I'm going wrong. Thanks.
Code:
#include <iostream>
using namespace std;
//Functions prototypes...
void instructions ();
int triangle ();
//----------------------------------
int main ()
{
instructions ();
triangle ();
return 0;
}
//--------------------------------------------------------------------------
// User instructions
void instructions ()
{
cout << "This program displays the numbers 1 through 4 "
<< "in incremental steps, " << endl;
cout << "starting with just 1 on the first line "
<< "and increasing each line by one digit " << endl;
cout << "until the fourth line has all 4 numbers. "
<< "It then starts displaying the numbers" << endl;
cout << "in decremental steps until the final line "
<< "just displays the number 1." << endl << endl;
} // End of instructions function
//-----------------------------------------------------------------
int triangle ()
{
//Local variables:
int horiz=0;
int vert=0;
for(int vert=1; vert<=4; vert++)
{
for(int horiz=1; horiz<=3; horiz++)
cout << "*";
{
for(int horiz=1;horiz<=vert; horiz++)
cout << "*";
}
cout << endl;
}
return 0;
}