Write a function IsOTriangle() that takes a size parameter and displays an isosceles triangle with that many lines.

I have to have it with a main(), IsoTriangle(), and Spaces()
Spaces() to display the leading spaces before the start of the asteriks.

Normally functions and calculations don't bug me to much, but when i'm doing "drawing" it messes me up.

#include <iostream.h>
 
//Prototypes
void IsoTriangle(int Height);
int Spaces(int Height);
//Main function, asks for height of triangle and then goes to IsoTriangle function
int main()
{
int Height;
cout << "Height of the Triangle? ";
cin >> Height;
IsoTriangle(Height);
return 0;
}
 
//--------------------------------------------------------------
void IsoTriangle(int Height)
{
int charlength, characters = 1;
int length = 0;
//Suppose to count till it reaches the height, accomplishes the task at this point.
for(int counter = 1; counter <= Height; counter++)
{
Spaces(Height);
charlength = Height - length;
// Repeats the while loop till it outputs the correct amount of asteriks
while(characters <= charlength)
{
cout << "*";
characters++;
cout << endl;
}
}
 
}
int Spaces(int Height)
{
int space, length;
if (space != 1)
{
length = Height - space;
space++;
}
else
{
int length = Height - space;
}
for(int counter = 1; counter <= length; counter++)
cout << " ";
space++;
return length;
}

Such as if i inputted 4 for the height i would get the output

*
***
*****
*******

with 3 spaces on the first line, 2 spaces on the second line, and 1 space on the third. So that from the bottom up it adds a space to each line.

Sigh, you know i'm looking at my coding and i don't even remember half of what i was trying, but i'm going to re-write it. Still if i don't get it i would love to have some input on what i can do.

Thank you in advance!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.