This is a discussion on Help with flawed algorithm? within the C Programming forums, part of the General Programming Boards category; Originally Posted by qny If the user types "<SPACE> <4> <2> <SPACE> <ENTER>" this will not consume the <ENTER>. It ...
Lol actually, Adak, it worked! I Had to tweak it a bit. But now I found another bug, prolly the last one! The code below is the mathematical algorithm the matrix does... The only problem is with division - if I enter numbers to divide - any numbers - it will tell me it failed (failed = the sum is NOT an integer!)
I tried a few variations but none worked...Code:switch (matrix[i][j]) { case '+': matrix[i+1][j] = (matrix[i-1][j]) + (matrix[i+1][j]); break; case '-': matrix[i+1][j] = (matrix[i-1][j]) - (matrix[i+1][j]); break; case '*': matrix[i+1][j] = (matrix[i-1][j]) * (matrix[i+1][j]); break; case '/': if ((matrix[i+1][j]) ==0 ) { printf("There is a division by zero"); return 1; } if (((matrix[i-1][j] / matrix[i+1][j])%2) != 0) { left=1; } if (left == 1 ) { printf("There is a non-integer division"); return 1; } matrix[i+1][j] = (matrix[i-1][j]) / (matrix[i+1][j]); break; }
The %2 thingy doesn't work for some reason.... and it enters the "Non Integer division" all the time! Even if : 1/1-1
Suggestions?
Probably because both matrix[i-1][j] and matrix[i+1][j] are Integers. Any way around that, tho? To save only the division's output? I tried putting it into float but it won't work...