Thread: While loop problem?

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    114

    While loop problem?

    Code:
    #include<iostream>
    #include<string>
    
    using namespace std;
    
    int main()
    {
        string input;
        int money = 0;
        int game = 1;
     
      while(game = 1)
       {
        cin >> input;
        
        if(input == "help")
        {
                 cout << "Type St00fs f0r St00fs t0 happen\n";
                 
        }    
        if(input == "awsome")
        {
                 cout <<"You Stumble along the dirt road and find a penny\n";
                 
                 money = money + 1;
                
        }
        if(input == "money")
        {
                 cout <<"You has " << money << " mooneys\n";
                
        }
        if(input == "gameover")
        {
                 cout <<"You die guiz guiz\n";
                 game = 0;
        }
                 
        
       }
       
    return 0;
    }

    I type gameover and then it still doesnt exit input loop

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    Classic. You used = instead of == in your condition.

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    114

    Omg lol

    Hey thanks simple problem with simple answer

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    If you would have turned on some warnings (like -Wall in gcc) then your compiler would have told you something looked weird about your while loop.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Addition problem in loop
    By murjax in forum C Programming
    Replies: 3
    Last Post: 07-01-2009, 06:29 PM
  2. validation problem in a loop (newbie question)
    By Aisthesis in forum C++ Programming
    Replies: 11
    Last Post: 05-10-2009, 10:47 PM
  3. For Loop Problem
    By xp5 in forum C Programming
    Replies: 10
    Last Post: 09-05-2007, 04:37 PM
  4. Loop problem
    By Tesnik in forum C++ Programming
    Replies: 29
    Last Post: 08-23-2007, 10:24 AM
  5. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM

Tags for this Thread