codecodecode codecodecode - 1 year ago 97
C++ Question

Creating a for loop to continue to count

what would be the code to continue counting with a for loop? like if i wanted put in a char and have it print once on the first line, twice on the second line, third on the third line and so on?

I've tried

for (int a; a<5; a++)
cout "L";

but this only prints one L per line

i need it to be more like


Answer Source

You need an additional loop if you do not want to use something like std::string. The inner loop will add L with it's respective amount per line to the output. Once all the amount of Ls are written, you end the line.

Something like:

int main() {

    for (int a = 1; a < 5; a++)
        for (int l = 1; l <= a; l++)
            std::cout << "L";
        std::cout << std::endl;

    return 1;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download