Can't make a Triangle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>

#include <string>

using namespace std;

void printLine(int);

void printTriangle(int);

int main()

{

int height;

cout << endl;

printLine(1);

cout << endl;

printLine(4);

cout << endl;

cout << "What is the height of the triangle? ";

cin >> height;

cout << endl << endl;

printTriangle(height);

cout << endl;

system ("pause");

return 0;

}

void printLine(int num)

{

string c = "*";

for (int i = 1; i <= num; i++)

{

cout << c << endl;

return;

}

}

void printTriangle(int num)

{

for (int i = 1; i <= num; i++)

{

cout << " ";

printLine(i);

}

cout << endl;

return;

}


I keep getting look something like this:

*
*
*


I need some help, comments please
closed account (jLNv0pDG)
line 55: return; is incorrectly in the for loop. It needs to be outside the braces on line 57. That's why you are only getting one * each time you call the function.
Last edited on
Topic archived. No new replies allowed.