*
     **
   ***
 ****

*****

i need to make a triangle like this for a homework assignment
heres what i have so far
im stuck on this
i must use for loops...when i compile it all it does is end the program

#include <iostream>
using namespace std;
int main ()
{
int lines;
int spaces;
int dots ;
cout << "How many lines do you want in the picture?\n";
cin >> lines;
for ( lines; lines == 0;    lines--){
    for (spaces = lines - 1; spaces <= 0; spaces-- ){
    cout << "_";
    for (dots = 1; dots <= lines; dots++ ){
    cout << '*';}
    cout << endl;}}
return 0; }

please help thanks

Greetings bluegoo06,

Doing this process is not hard at all. I commented the code to help you understand.

#include <iostream>
using namespace std;

int main () {
	int lines;
	int start = 0;
	int dots;
	cout << "How many lines do you want in the picture?\n";
	cin >> lines;
	// Make sure
	while (start < lines) {
		// We start at 0, then gradually increment
		for (dots = 0; dots <= start; dots++)
			cout << "*";
		cout << endl;
		start++;		// Increment
	}

	return 0;
}

Hope this helps. If you have any further questions please feel free to ask.

- Stack Overfow

Bluegoo06:

We're helping you in this thread, no need to make another thread. Just keep discussion of your problem in here!

use a nested while lo0p...(much easier for me)

int i=1;
    while(i<value){
            int a=0;
            while(a<i){
            cout<<"*";
            a++;
        }
    cout<<"\n";
    i++;
    }
}

[fix]
I use a nested while lo0p because it's much easier for me
[/fix]

Not everyone feels the same way as you, so don't push your opinions on anyone unless you state explicitly that they're opinions first.

>Doing this process is not hard at all.
No, it isn't.

>I commented the code to help you understand.
Too bad the code does something completely different from the OP's problem. If you had read the code posted originally then you would have seen that the problem was not this:

#include <iostream>

int main()
{
  for ( int lines = 0; lines < 5; lines++ ) {
    for ( int stars = 0; stars <= lines; stars++ )
      std::cout.put ( '*' );
    std::cout<<std::endl;
  }
}

But rather this (code enhanced to avoid plagiarism):

#include <iostream>
#include <iomanip>

int main()
{
  const int lines = 5;

  for ( int i = 1; i <= lines; i++ ) {
    std::cout<< std::setfill ( ' ' ) << std::setw ( lines - i ) <<"";
    std::cout<< std::setfill ( '*' ) << std::setw ( i ) <<""<<std::endl;
  }
}

An assignment that would most likely give way to this:

#include <iostream>
#include <iomanip>

int main()
{
  const int lines = 5;

  for ( int i = 1; i <= lines; i++ ) {
    std::cout<< std::setfill ( ' ' ) << std::setw ( lines - i ) <<"";
    std::cout<< std::setfill ( '*' ) << std::setw ( i * 2 - 1 ) <<""<<std::endl;
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.