c++ - Issue with 2D arrays and for loop -


im new c++ programming , have issue 2d array , loop.. looking solution on program made recently, else works good. except loop.

this small part of program, seems problem on code. program test. there 5 questions 3 answer options , user should enter 1, 2, 3 (int values, function responsible getting these values atsakymai[] array working tho). jdm, usdm, eudm arrays should keep points right answer (they set 0 @ start). atsakymoverte array keeps answers order points depends on. ex. 1 - +1 point jdm; 2 - 1+ usdm; 3 - 1+ eudm.

this program seems work until loop reaches y = 4. after gives bad values... first 3 times loop works , increments right variables(variables jdm, usdm or eudm arrays) one. works until 4th time in loop... have no idea should change working right. sitting beside problem few hours, yeah... no solution. hope guys understand problem. thanks.

int *jdm = new int[6](); int *usdm = new int[6](); int *eudm = new int[6]();  int atsakymoverte[6][4] = { {0,0,0,0}, {0,2,1,3}, {0,2,1,3}, {0,1,2,3}, {0,3,1,2}, {0,3,1,2} };  (int y = 1 ; y < 6; y++) {         (int x = 1; x < 4; x++) {            if (atsakymai[y] == atsakymoverte[y][x]) {            switch (x) {                 case 1: jdm[y]++;                     break;                 case 2: usdm[y]++;                     break;                 case 3: eudm[y]++;                     break;            }         }     } } 

don't know c++ - though many other languages have 0-index arrays. means 0 first element.

so instead of

for (int y = 1 ; y < 6; y++)         (int x = 1; x < 4; x++) 

it should be

for (int y = 0 ; y < 6; y++)         (int x = 0; x < 4; x++) 

by using loop have @ moment, first pass has y equal 1 - atsakymai[1] - 2nd element in atsakymai array, not first.

if you're not careful, can end trying reference index doesn't exist.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -