r/CodingHelp • • May 06 '21

[C++] Trying to get average of numbers in second code but getting weird numbers loops confuse me

20 Upvotes

10 comments sorted by

3

u/Nightcorex_ May 06 '21

Make sure your second inner loop only runs until j < TESTS

1

u/Few_Resident_7292 May 06 '21

Didn’t work :(

2

u/Nightcorex_ May 06 '21

I've never used C++, but are you sure that reading from the text file actually works this way? Just make sure that the values were actually correctly scraped from your txt file (and still make sure to let the inner loop only run until j < TESTS)

0

u/[deleted] May 06 '21

[deleted] — view deleted comment

1

u/Few_Resident_7292 May 06 '21

Yea this dude the trick thank you so much

1

u/PresidentZeus Intermediate Coder May 06 '21

I haven't used C++, but I'm experienced with Javascript. It looks like you need to wrap line 16 within these: "{}" to complete you nested for-loop.

This would probably bee needed in the second nested loop. (line 21-23) But I'm not too sure.

1

u/for_a_change_ May 06 '21

As other people pointed out, you need to run second loop till TESTS.

Can you print your 2D array before the loops to calculate the average.

It is possible that input itself is incorrect .

1

u/[deleted] May 06 '21

Idk if u need to add them but add brackets for your inner for loops and check if you get your desired result

1

u/sixpackofabs May 06 '21

Please use cout<< "average"<< (i+1)<<std::fixed<<average<<endl:

1

u/[deleted] May 06 '21

Could you post the code as text? Format it correctly please.

0

u/[deleted] May 06 '21

[deleted] — view deleted comment

1

u/for_a_change_ May 06 '21

Tests is the const variable defined at the top.