Please Help Me Condense A Small Piece Of Code

i just finished a fairly large program, and now im trying to condense certain parts down (if possible)

I have this at the top of my code...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
struct Songs song1; song1.count = 0;
struct Songs song2; song2.count = 0;
struct Songs song3; song3.count = 0;
struct Songs song4; song4.count = 0;
struct Songs song5; song5.count = 0;
struct Songs song6; song6.count = 0;
struct Songs song7; song7.count = 0;
struct Songs song8; song8.count = 0;
struct Songs song9; song9.count = 0;
struct Songs song10; song10.count = 0;
struct Songs song11; song11.count = 0;
struct Songs song12; song12.count = 0;
struct Songs song13; song13.count = 0;
struct Songs song14; song14.count = 0;
struct Songs song15; song15.count = 0;
struct Songs song16; song16.count = 0;
struct Songs song17; song17.count = 0;
struct Songs song18; song18.count = 0;
struct Songs song19; song19.count = 0;
struct Songs song20; song20.count = 0;



Is there anyway to go through a loop to to condense this?
something like...
for(int i = 1; i <= 20; i++)
{
struct Songs song + i; song + i.count = 0;
}
I know that for loop won't work that way, but is there some way to do something like that?
Can't you use an array of Songs?

[edit]
Good grief! What is wrong with people?
http://www.cplusplus.com/forum/beginner/41641/
Last edited on
Seriously, if you've gone as far as structs but you can't figure out when to use arrays maybe you should take a step back and make sure you really do understand.
no each struct has a bunch of information about each song....

im reading in song names with a bunch of information about each song from a separate file....so no i don't need to use an array
Last edited on
Then you need to take a step forward (or is it sideways?) and learn about 'classes' and default constructors. Redundent declarations like this are something you'd see in a script not an object oriented language.
I think constructors and array use would make this code a lot better.
so......is there a way to condense it or not?
"constructors and array use"

There's a good 'documentation' section on this website that will explain it all for free, too...
http://www.cplusplus.com/doc/tutorial/classes/

I'm assuming you're familiar with arrays already.
HA
Topic archived. No new replies allowed.