# Help with flawed algorithm?

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 12-07-2012
Quote:

Originally Posted by qny
If the user types "<SPACE> <4> <2> <SPACE> <ENTER>" this will not consume the <ENTER>.

It presumes the user is not a drunken sod, at that time - true. ;)
• 12-07-2012
Gal Abir
Lol actually, Adak, it worked! I Had to tweak it a bit. But now I found another bug, prolly the last one! :D 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!)

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;         }```
I tried a few variations but none worked...

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?
• 12-07-2012
Gal Abir
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...
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12