|
hi all,
i am working on a basic challenege for my course in C#, i have got to the point where i need the loop to do its actions until 2 statements become true but my program runs through the loop once and one statement becomes true and other false and then it jumps out of loop so i need to know what i have done wrong with the code or any advice please?
int z = 2;
if (remaindernum != 0 & remainderden != 0)
{
while (z <= totala)
{
while (remaindernum != 0 & remainderden != 0)
{
remaindernum = (newfraction % z);
remainderden = (totala % z);
z += 1;
}
}
}
just to clarify pretending my first line of code is 0,
it runs through fine till line 15 then goes back into loop at line 7 but then jumps down to line 16 and sticks in neverending loop
|
|
|
|
|
I suspect you want OR rather than AND. You may also want to use the Logical operators rather than the Bitwise ones.
|
|
|
|
|
basically its a loop to simplify a fraction , so i need that loop to keep running until both statements are true?
|
|
|
|
|
also should i be using a do statement for this kind of thing?
|
|
|
|
|
|
You are using the wrong operator, it should be the double ampersand thus:
if (remaindernum != 0 && remainderden != 0)
One of these days I'm going to think of a really clever signature.
|
|
|
|