Thread: ifs for pointers?

  1. #1
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128

    ifs for pointers?

    Just wondering if something like this,

    Code:
        if (NewUser.location = &rooms[1])
    {
            some function
    }

    Would fit into this,

    Code:
    	while (1)
    
    {
    
            // Display the players location and possible movements.
    
    		cout << "------------------\n" << endl;
    		cout << "Location:   " << NewUser.location->name << endl;
    		cout << "\nDescription:\n\n" << NewUser.location->description << "\n" << endl;
    		if (NewUser.location->north)
    			cout << "(N)orth to: " << NewUser.location->north->name << endl;
    		if (NewUser.location->south)
    			cout << "(S)outh to: " << NewUser.location->south->name << endl;
    		if (NewUser.location->east)
    			cout << "(E)ast to:  " << NewUser.location->east->name << endl;
    		if (NewUser.location->west)
    			cout << "(W)est to:  " << NewUser.location->west->name << endl;
    		cout << "(Q)uit" << endl;
    
    		// Get input and decide where to go next.
    
    		char input;
            string inputString;
    
            getline(cin,inputString);	        // Grab everything in the buffer, even if it's more than one character.
    
            input = inputString[0];	            // Only use the first character, discard the rest.
    
    		if (input == 'q')
    			break;
    
                    cout << quizMaster.poseQuestion().c_str() << endl;
                    getline(cin, answer);
    
    		if (quizMaster.isCorrectAnswer(answer))
        {
                    	cout << "Thats right" << endl;
    
    			if (input == 'n' && NewUser.location->north)
    				NewUser.location = NewUser.location->north;
    			if (input == 's' && NewUser.location->south)
    				NewUser.location = NewUser.location->south;
    			if (input == 'e' && NewUser.location->east)
    				NewUser.location = NewUser.location->east;
    			if (input == 'w' && NewUser.location->west)
    				NewUser.location = NewUser.location->west;
        }
    
        else
                {
                cout << "Better luck next time !" << endl;
                }
    
    }
    to add a bit of functionality into my game

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Assuming you remember to change = to ==, and the name "rooms" is visible.

  3. #3
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Ok thankyou, I keep forgetting the = x 2 gah.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Numerical order with ifs question?
    By JDrake in forum C++ Programming
    Replies: 5
    Last Post: 11-04-2006, 01:29 PM
  2. Question With Nested If's
    By jarvis in forum C Programming
    Replies: 7
    Last Post: 07-26-2006, 08:06 AM
  3. Try...catch...throw or ifs?
    By Kylecito in forum C++ Programming
    Replies: 9
    Last Post: 03-02-2006, 10:41 PM
  4. Very new to C++ or other programming, stuck on IF's
    By ivanlucrazy in forum C++ Programming
    Replies: 13
    Last Post: 10-16-2003, 08:59 PM
  5. Single else for two ifs.
    By Juganoo in forum C Programming
    Replies: 6
    Last Post: 12-23-2002, 03:00 PM