# More noob C++ programmer help



## Lampmaster (Dec 3, 2009)

Hey guys, one last problem here.

I have this function for outputting an array



> //	===================
> //	Function PrintArray
> //	=============================
> void PrintArray( string name,
> ...



As it is, it outputs one element per line. Is there a way to make it output 10 elements per line?


----------



## GSquadron (Dec 3, 2009)

The only way to output 10 lines is to get a library that integrates in the C++ as a function and does the same think again and again. Only experts do that. I did it with Nvidia's link libraries and it should always start like <stdio.h> or in this case <repeat.h>. The sqrt for example could not be known as a command if u dont put the <math.h> at the start below #include#. Maybe u can do that yourself, integrating the dll in your C++, but it needs specific commands which u need to know before using it. Otherwise.... ERROR


----------



## dcf-joe (Dec 3, 2009)

If I understand correctly what you are asking, yes you can have ten outputs per line. Think about those simple c++ programs that make pyramids and stuff with numbers. I can give you further information if you need it, but a hint for right now is that it would require nested for loops.


----------



## Kreij (Dec 4, 2009)

Create a variable to do the ten count. Reset the variable when it reaches 10. No need for nested loops.

```
ii = 0;
tenloop = 1;
while (ii < numberOfElements)
{
    cout << stuff to output with no endl;
    ii++;
    tenloop++;
    if (tenloop == 11)
    {
          cout << endl;
          tenloop = 1;
    }
}
```


----------



## Lampmaster (Dec 4, 2009)

Awesome, that's exactly what I needed.


----------



## Kreij (Dec 4, 2009)

When learning to program, it's sometimes difficult to wrap your head around the logic that you need to perform a given function. Stop and think it though.
The idea is to make it as simple as possible and write the least code you have to, to accomplish the task at hand. There are many ways to code things, but if you can work toward the simplest way it removes superfluous code and makes it easier to understand, debug and maintain.


----------



## dcf-joe (Dec 4, 2009)

You can also do

for(elementNumber = 0; elementNumber < arraySize; elementNumber++)
{
      if((elementNumber + 1) % 10 == 0)
      {
           cout << list[elementNumber] << endl;
      }

      else
      {
           cout << list[elementNumber] << " ";
      }
}


----------

