I've been trying to do this asteriks triangle with nested loop for days and many hours and still no luck. Im using visual studio 2010 and I've been searching the web for clues and everytime I use the cout, anything iostream, const char and more it always fails I'm not sure if its not compatible with Vistual Studios or what is exactly the issue but I'm new to programming so I'm struggling a lot with this and have restarted the program 4 times completely already. My assignment includes only 1 button and a multiline text box. When the user clicks the botton a right triangle with one astriks at the top and increasing by one the last row has 8 astriks for example ...

*
**
***
****
*****
******
*******
********

With my current code I'm working on nothing happens at all in the text box and Ive used so many different codes already but the closest I got was only one pathetic "*"

     int row, col;

      String^value;



      value += "*";

    for(row = 9; row > 1; row++){ 
    for(col = 1; col < 9; col--){ 


    value += "\r\n";

    }



    txtBox->Text += value;

    }
         }      

         };

Any input would be greatly appreciated and if by chance someone could also explain the iostream and cout used in visual studio or if its even possible with visual studio 2010 we .
haven't gone over that at all in class yet I've only seen it on the internet trying to search for help. Thank you so much!

Any reason you are trying to use CLR/C++ instead of just c++? Create a c++ (or c) win32 console program, then call cout to display each asterisk and space. No need to store them in a std::string variable.

Because of the markup language used in this editor it's impossible to tell if you are attempting to display a triangle of stars where there are spaces before each row of stars? Or just rows of stars as shown in your post. The markup language removes leading spaces so I don't know which you need to display.

so part of the code I'm entering is not for C++? I've been searching all over the web and have created so many different programs I'm honestly not sure I've been adding and deleting out all different parts. What part exactly in the code is CLR/C++? I'm sorry I have no experience with programing so I really dont know the difference. No space is needed before each row of stars triangle sorry. I've restarted again with the program and this is the code I have now ive been trying to use namespace std; but always get errors. Im also getting an error now that I'm missing a match to a "{"

#include <iostream>

using std::cout;
using std::vector; 
using std::endl;

//vector<int> v(10); 



intmain() 

std::cout << "*";


{for (int i = 11; i >= 1; i--)

{ 

for(int n=0;n<i;n++)

//cout << '*';

//cout << '\n';

n=0;    

String^value;

That's CLR/C++, not c++

line 11: missing a space between int and main()

line 12: missing { to tell the compiler its the start of a function. Then you need } after libne 26 to indicate the end of the function. For every { you need a }. It is best if you align them up then indent code two or three spaces.

line 16: the { at the beginning of that line is not needed. Delete it.

You need to pay close attention to where you put { and }, don't just put them in random places. The code you posted should look like this:

#include <iostream>

using std::cout;
using std::vector; 
using std::endl;

//vector<int> v(10); 



int main() 
{
   cout << "*";


    for (int i = 11; i >= 1; i--) // <<< this will print the stars upside down because the loop counts backwared
    { 

        for(int n=0;n<i;n++)
        {
            //cout << '*';
        }
        //cout << '\n';
    }

    n=0; // <<<< Error, undeclared variable
}
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.