function - C++ - Variable Decrement -
heys.
i have code, sets table mystery reason. size 6x60. means sizey defined 6, , sizex 60.
void set_table(char** table) { int i,j,k=0; for(i=0;i<sizey;i+=3){ for(j=0;j<sizex;j++){ switch(k++%5){ case 0: table[i][j]='|'; break; case 1: table[i][j]=' '; break; case 2: table[i][j]=(char)((((k-2)/50)%10)+48); break; case 3: table[i][j]=(char)((((k-3)/5)%10)+48); break; case 4: table[i][j]=' '; break; default: continue; } } } }
i doing 3 variables, can see. question is, can 2 variables, or 1 ?
thanks in advance.
here's simplification you:
switch(k++%5){ case 0: table[i][j]='|'; break; case 1: case 4: table[i][j]=' '; break; case 2: case 3: table[i][j]= '0'; break; default: continue; }
with c++, 1 case can fall another, such cases 1 , 2 above.
your expressions case 2 , 3 can simplified. i'll use case 2 example:
((((k-2)/50)%10)+48)
substituting 2 k yields
((((2-2)/50)%10)+48)
simplify:
((((0)/50)%10)+48)
0 divided zero, simplifying again:
(((0)%10)+48)
0 mod zero, since involves division:
((0)+48)
simplifying:
(48)
replacing equivalent character (since array char
):
'0'
Comments
Post a Comment