13,085,936 members (92,813 online)
Rate this:
See more:
```void flip ( int i )

{
assert( i==1 && i==0);
if(i = 1)
i=0;
else
i=0;
}

int main()
{
int i = 1;
assert(i==1);
flip(i);
assert(i==0);
flip(i);
assert(i==1);
cout << "Success!\n";
return 0;
}```

Posted 12-Feb-13 18:21pm
Updated 12-Feb-13 18:44pm
H.Brydon35.8K
v2

Rate this:

## Solution 1

The assertion in flip() will always fail because you are trying to assert that i is equal to both 0 and 1. You also change the value of i (locally) to zero regardless of input value.

The call to flip() does not change the value of i in main(). You need to make flip refer to the variable i instead of a copy of its value: ie. "void flip(int* i)".
Albert Holguin 13-Feb-13 18:16pm

Good input... but there are oh so many errors in that code. :)
Rate this:

## Solution 2

Couple of things, i think are wrong

```assert( i==1 && i==0); // Why &&. I think this should be ||
if(i = 1)
i=0;
else
i=0;   // Here you will have to set i = 1 (assuming this is what flip function is supposed to do```

EDIT: the "=" in your if conditions should be changed to "=="
v2
Albert Holguin 13-Feb-13 18:13pm

You missed the `if(i=1)` error, that's setting the value to 1 all the time.
Rahul Rajat Singh 13-Feb-13 23:15pm

OOPs, My bad. I will correct the mistake. Apparently I am spending too much time with sql nowadays and this "=" started seeming ok with if :)
Mas11 13-Feb-13 23:39pm

Top Experts
Last 24hrsThis month
 Graeme_Grant 170 OriginalGriff 143 Jochen Arndt 140 Kornfeld Eliyahu Peter 140 BillWoodruff 80
 OriginalGriff 3,095 Graeme_Grant 1,519 ProgramFOX 1,367 ppolymorphe 1,217 Jochen Arndt 1,205