Breaking a Loop Problem

November 11, 2010 at 16:51:54
Specs: Windows 7
Hi I am writing code to perform the game of Go Fish! I have most of the code written and while this may be a small and trivial error I can't seem to find why my loop won't break. My code up until now is seen like this:

 while(Guess = 1){
        cout << endl << "You ask if I have any: ";
        cin >> Ask;
        for(int a=0; a<CSize; a++) {
            if(Computer[a] == Ask){
                Player[PSize] = Computer[a];
                if(a != CSize){
                    Computer[a] = Computer[CSize - 1];
                }
                if(a == CSize){
                    Computer[a] = 'null';
                }
                PSize++;
                CSize--;
            }
            else if(Computer[a] != Ask){
                fail++;
                if(fail == CSize){
                    Guess = 0;
                }
            }                
        }
        cout << endl << "Your hand is now: " << endl;
        for (int c=0; c<PSize; c++){
            cout << Player[c] << " ";
        }
       cout << endl << "Superguy: " << endl;
        for (int c=0; c<CSize; c++){
            cout << Computer[c] << " ";
        }
    }

    if(Guess == 0){
        cout << endl << "I do not have " << Ask << "! Go Fish!" << endl;
        GoFish(x);
        if(x == Ask){                    
            PlayerTurn(PSize, CSize);
        }
    } 


See More: Breaking a Loop Problem

Report •


#1
November 12, 2010 at 07:15:02
while(Guess = 1){
You're assigning 1 to Guess, which is true.

How To Ask Questions The Smart Way


Report •
Related Solutions


Ask Question