I'm new and I'm trying to figure out the problems with this triangle but can't after a week of trying. If I could just see the right code I think I would understand this really good.
#include <iostream>
int drawBar(int);
int main()
{
std::cout << std::endl << "Let's Draw a triangle!\n";
//determine how many lines will be drawn
int triangleBase = 0;
//draw the triangle
for (int i = 0 ; i >= triangleBase ; i--) {
drawBar(i);
}
return 0;
} //end main
int drawBar(int barSize) {
//draws a line of asterisks
//the number of asterisk drawn equals barSize
why is the function an int if its return value has no impact? (Make it a void).
Why initiate i at 0 and then check if it's larger than triangleBase (which is also being initiated at 0, try swapping some numbers around, such as do this whilst i is smaller than triangleBase)
since I had nothing better to do i fixed the code for you aswell
#include <iostream>
void drawBar(int);
usingnamespace std;
int main()
{
cout << endl << "Let's Draw a triangle!\n";
//determine how many lines will be drawn
int triangleBase = 5; // Initiate at random value
//draw the triangle
for (int i = 1 ; i <= triangleBase ; i++) // While i is smaller than or equal to triangleBase - Edit: realised there's no point starting at 0
{
drawBar(i);
}
system("PAUSE"); // Crude but works for personal projects
return 0;
} //end main
void drawBar(int barSize)
{
while (barSize != 0)
{
barSize--;
cout << '*';
}
cout << endl;
}