![]() |
|
|
#1 | |
![]() Join Date: Aug 2009
Location: Washington The State
Posts: 149 (0.11/day)
Thanks: 35
Thanked 17 Times in 14 Posts
|
More noob C++ programmer help
Hey guys, one last problem here.
I have this function for outputting an array Quote:
|
|
|
|
|
|
|
#2 |
![]() |
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
|
|
|
|
|
|
#3 |
![]() Join Date: Feb 2008
Location: Nebraska, USA
Posts: 327 (0.17/day)
Thanks: 61
Thanked 18 Times in 18 Posts
|
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.
|
|
|
|
| The Following User Says Thank You to dcf-joe For This Useful Post: |
|
|
#4 |
|
Hardcore Monkey Moderator
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 12,254 (5.27/day)
Thanks: 591
Thanked 5,510 Times in 2,948 Posts
|
Create a variable to do the ten count. Reset the variable when it reaches 10. No need for nested loops.
Code:
ii = 0;
tenloop = 1;
while (ii < numberOfElements)
{
cout << stuff to output with no endl;
ii++;
tenloop++;
if (tenloop == 11)
{
cout << endl;
tenloop = 1;
}
}
|
|
|
|
| The Following User Says Thank You to Kreij For This Useful Post: |
|
|
#5 |
![]() Join Date: Aug 2009
Location: Washington The State
Posts: 149 (0.11/day)
Thanks: 35
Thanked 17 Times in 14 Posts
|
Awesome, that's exactly what I needed.
|
|
|
|
|
|
#6 |
|
Hardcore Monkey Moderator
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 12,254 (5.27/day)
Thanks: 591
Thanked 5,510 Times in 2,948 Posts
|
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.
__________________
Cloud (noun, singular): A dynamic arrangement of multiple potential single points of failure, with a user at one end and their data at the other. Get more tech news on a wide variety of topics at NextPowerUp
|
|
|
|
|
|
#7 |
![]() Join Date: Feb 2008
Location: Nebraska, USA
Posts: 327 (0.17/day)
Thanks: 61
Thanked 18 Times in 18 Posts
|
You can also do
for(elementNumber = 0; elementNumber < arraySize; elementNumber++) { if((elementNumber + 1) % 10 == 0) { cout << list[elementNumber] << endl; } else { cout << list[elementNumber] << " "; } } |
|
|
|
| The Following User Says Thank You to dcf-joe For This Useful Post: |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Noob programmer help | Lampmaster | Programming & Webmastering | 6 | Nov 25, 2009 07:04 PM |
| Looking for a good Java Programmer | Wastedslayer | Programming & Webmastering | 3 | Apr 9, 2009 11:31 PM |
| Couple more quesions for a somewhat noob OC'er ;) | Pepsiaddict | Overclocking & Cooling | 4 | Nov 30, 2006 02:40 PM |
| im a noob at overclockin... help me! | karolpl2004 | Overclocking & Cooling | 12 | Dec 3, 2005 11:03 PM |