hello all;

i'm having a problem with my output. the program that i'm writing is supposed to take a number input than display the output as asterisks. so if the input is 4 the output should be:
*
**
***
****

however, i'm just getting a single column of asterisks. i know its late and i'm probably making a mental err. thanks for the help:

#include <iostream>
#include <iomanip>

using namespace std;

	int main()

	{
		int input_1;
		int count;
		input_1 = 0;
		count = 0;

		cout<< "Enter any positive number :  ";
		cin>>input_1;
		cout<< input_1 << endl;  //this is to test the input only
//need to verify for a positive number and make sure that letters are not used

		for (count = 0; count < input_1; count++)
		{
		for (count = 0; count < input_1; count++)
		cout<< " * " <<endl;
		}

		return 0;
		}

Edited 6 Years Ago by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

Move the endl in the for loops outside of the first one so it's only called once per row. Also, you don't verify that your input fulfills those criteria you just print it out. See this thread to get some idea of what's involved. If that's a lot, simply test whether then number is positive.

Also, please learn to use code tags:

[code]

//code goes here

[/code]
(just like HTML but with [] -- or just highlight your code and hit the

button in the toolbar).[code]
button in the toolbar).

Edited 6 Years Ago by jonsca: n/a

jonsca;
thanks for your quick reply and advice. however, i'm unclear on what you mean by moving endl? can you explain a little more so that i may have a better understanding of my mistake.
again,
thanks

This is your loop:

for (count = 0; count < input_1; count++)
{
     for (count = 0; count < input_1; count++)
        cout<< " * " <<endl;
}

Trace through your loop the way you have it, it's going
* (+newline)
* (+newline)
* (+ newline)
*
since you have an endl after each star. Your inner loop need to print the entire row of stars so keep endl out of it. Put 1 endl just outside of the inner loop so that you catch it each cycle (after a row is written) through the outer loop.

Edited 6 Years Ago by jonsca: n/a

thanks!! for clearing that up for me. however, i'm still having problems with my logic. instead of having x number of asterisks per line, now i'm just getting same number of asterisks in a stragiht line.

can you give me a hint on how to make the output look like this:
example; input = 5
output is:
*
**
***
****
*****
again thanks;

Well you need to put a cout << endl; within your outer loop at the end so that you get it each time you complete a row

for (outer loop over rows)
{
    for (inner loop over each star in the row)
        print the star

    cout <<endl; //now we go to the next line
}

Edited 6 Years Ago by jonsca: n/a

thanks for your help.. i figured out my problem. the problem was with my syntax in the for loop boolean expression.

This question has already been answered. Start a new discussion instead.