Write out a triangle

Pages: 12
ok, i see it is a simple trade out of commands, I will start using it, thanks :)
You should be aware that although "\n" and "endl" look visually similar (in the actions they perfrom) they are different and it is advised to use "\n".

http://www.cplusplus.com/reference/iostream/manipulators/endl/

EDIT* Advised for this program ^
Last edited on
I would suspect that the point of the assignment is to use nested for loops.

Clever ways to simplify problems are much more fun, though. Here's mine:
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
#include <iostream>
using namespace std;

int main( int argc, char* args[] )
{
    char sign;
    int height;

    cout << "designate sign: ";
    cin >> sign;

    cout << "designate height: ";
    cin >> height;

    cout << endl;

    string line;
    for( int i = 0; i < height; ++i )
    {
        line += sign;
        cout << line << endl;
    }

    return 0;
}
Last edited on
You should be aware that although "\n" and "endl" look visually similar (in the actions they perfrom) they are different and it is advised to use "\n".
Uh... Huh? Actually, they do almost exactly the same. In fact, if I had to guess, I'd say std::endl() just pushes an '\n' into the stream.
Doesn't endl also flush the stream?
Doesn't endl also flush the stream?

That's what I thought.
Last edited on
Streams are line-buffered. std::endl() flushes the stream as an indirect consequence of pushing the newline.
(I think.)
Last edited on
ok, got it, so there is a difference, thanks Mcleano and Bazzy
Topic archived. No new replies allowed.
Pages: 12