I'm not going to post the code on this one just incase it's a little confusing. But here's the jist:

I have a couple of nested loops with multiple (var)++'s inside as counters. Each counter resets itself after reaching 25 and the total of the counters much equal 120 in order to print (No this is not a brute force cracker). Each (var)++ has a value associated with it that I have loaded as float variables.

Ex.
float valueA1 = 12.2
float valueA2 = 11.5
float valueA3 = 14.9
float valueA4 = 17.9

a++ reaches 3

cout << valueA(value of a) <<< this would be seen as valueA3

the print out desired would be 14.9

I apologize if this has been touched on and missed it in a search. I'm an old-timer trying to pick back up in the trade. Any constructive comment would be appreciated, even if it doesn't solve the issue.

## All 2 Replies

I think the best way to do it is using a float array.

float valueA[ 4 ] = { 12.2 , 11.5, 14.9, 17.9 };

For example when a == 3,
cout << valueA[a - 1] ;//<<< this would be seen as valueA3
I think you understand why I put a - 1, instead of just a. Also you should make sure that the value a can get is greater than 0, always. Otherwise a -1, will be -1, and give you an out-of-bounds error.

Thank you... that makes perfect sense. And each of the counters are initialized at 3 and reset to 3 after 25. I shouldn't be getting an out-of-bounds error. Also given my lowest value is 3, I'll set things as A-3 to hit the 0 placement properly (3 calls 0, 4 calls 1, 5 calls 2, etc). Thanks again.

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.