Friday, July 31, 2009

I don't know what's up with the code.?

#include%26lt;iostream%26gt;


int main()


{


using namespace std;


int a=20,b=100,c,d=0;





while((a!=0)||(b%26gt;c))


{


c=2*d;


a--;


d++;


}





cout%26lt;%26lt;" "%26lt;%26lt;c;


cout%26lt;%26lt;" "%26lt;%26lt;a;





return 0;


}








i've tried to compile this with my school lab's linux compiler and visual c++ but it just hangs... only when i place some obscure number like 31 will output show.





is there something wrong with the code? the logic? thanks for helping.

I don't know what's up with the code.?
You forgot to initialize c. Set c=0 initially, so you don't have a problem on the initial b%26gt;c comparison.
Reply:u shud use %26amp;%26amp; instead of ||


i think it will help
Reply:Not setting c to a value might be one problem.





Another is while b%26gt;c





In the loop


c = 2*0 = 0


and b never gets changed





It never exits the loop because 100 %26gt; 0 is true
Reply:wat?

lady palm

No comments:

Post a Comment