   Loop problem
  Ok im a noob and i have a little problem with this code   bool cointoss(){int toss;int loop = 0;bool heads;string coinflip;bool winflip = 0;while (loop = 0){getline(cin, coinflip);cout << endl;if((coinflip == "heads") || (coinflip == "HEADS") || (coinflip == "Heads")){loop = 1;heads = 1;}if((coinflip == "tails")  || (coinflip == "TAILS") || (coinflip == "Tails")){loop = 1;heads = 0;}}srand(time(NULL));toss = (rand() % 2);if((heads == 1) && (toss == 1)){winflip = 1;}if((heads == 0) && (toss == 0)){winflip = 1;}return winflip;}The problem is that it skips the loop, doesnt ask for user input and so returns 0 back to my main code.. can any one help me out here? 
  I noticed this line:while (loop = 0)You surely mean "while (loop == 0)". ;  while (loop = 0)trywhile (loop==0)bah. beat me to it.  [edited by - soddit on February 17, 2004 7:49:03 AM];  Ah thanks.. careless on my part.. its sorted now. ;  Many C and C++ programmers have an idiom of reversing such checks, as:if (0 == loop)The reasoning is that if you accidentally type a single = here, it will be flagged as a compiler error instead of messing up at runtime (because 0 isn''t an lvalue). The down-side is that you''re writing this backwards and unintuitive thing In Java, "if (loop = 0)" would be a compiler error anyway, because the language does not implicitly cast the integer result of the assignment to boolean, and the compiler complains that your conditional doesn''t have boolean type. (So the "0 ==" idiom is absent among Java programmers, at least those with Java as a "first language"  ) This has the up-side of preventing you from doing silly things, but the down-side that you have to add extra "== 0" bits when you are doing stuff like bitmasking:if ((mybitmask & 137) == 0) ;quote:Original post by Zahlman  In Java, "if (loop = 0)" would be a compiler error anyway, because the language does not implicitly cast the integer result of the assignment to boolean, and the compiler complains that your conditional doesn''t have boolean type. (So the "0 ==" idiom is absent among Java programmers, at least those with Java as a "first language"  ) This has the up-side of preventing you from doing silly things, but the down-side that you have to add extra "== 0" bits when you are doing stuff like bitmasking:if ((mybitmask & 137) == 0)   It also has the potential downside that the exact same program exists in Java. The only difference is that unlike C/C++ (which originally didn''t even have distinct boolean types, IIRC), Java does not accept implicit casts of numeric types to boolean truth values, but if the expression happens to assign a boolean value ... 