whats a bool

This is a discussion on whats a bool within the C++ Programming forums, part of the General Programming Boards category; i have a question whats a bool and what does it do i read it but it dont make snes ...

  1. #1
    Registered User Joe100's Avatar
    Join Date
    Jul 2003
    Posts
    63

    whats a bool

    i have a question whats a bool and what does it do i read it but it dont make snes to me

  2. #2
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    bool is TRUE or FALSE...

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    134
    bool returns true or false depending on the condition

    for example, since i is 0 it will return true (in otherwords 1), otherwise it would return 0 if false.

    Code:
    foo()
    {
    
        int i=0
        if( i==o)return true;
       else return false;
       
    }
    *Code tags finished by kermi3 (you forgot the bottom one)
    Last edited by noob2c; 08-02-2003 at 07:00 PM.

  4. #4
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Originally posted by gcn_zelda
    bool is TRUE or FALSE...
    Actually, compiling for windows, BOOL is either TRUE or FALSE (it's an enum), whereas bool is true or false (bool, true, false are C++ keywords).

    A boolean variable (bool) has only one of 2 values, it is either true or false.

  5. #5
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    oh yeah. My bad.

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    bool is a variable type, and variables of type bool can have one of two values: true or false. Here is an example:
    Code:
    #include<iostream>
    using namespace std;
    
    int main()
    {
    	bool answer;
    
    	answer = false;
    
    	if(answer == true)
    		cout<<"You correctly answered the question.\n";
    	else
    		cout<<"You're answer was incorrect.\n";
    
    	return 0;
    }

  7. #7
    Registered User Joe100's Avatar
    Join Date
    Jul 2003
    Posts
    63
    oooo so what ur saying u need bool to figure out a true or false answer in the computer world right?

  8. #8
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Originally posted by Joe100
    oooo so what ur saying u need bool to figure out a true or false answer in the computer world right?
    was that supposed to be some kind of Sarcasm ooooooo

  9. #9
    Registered User Joe100's Avatar
    Join Date
    Jul 2003
    Posts
    63
    nope its just that im trying to understand everything i always say oooooooo i dunno why

  10. #10
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    It's a type of variables that can store one of two possible values: a bool variable can either have the value true or false (be true or false).

    It isn't that much different from a a type like int. The only thing that might be strange at first is that it doesn't store a number but... uhm...one of two possible words: true or false. But don't get this wrong, it's not a string or something like that. It's not a numeric type either, but close to it.

    Code:
    int a, b;
    bool somebool;
    
    a = 1;
    b = 2;
    somebool = (a==b);
    
    if (a==b) {
    	cout << "(a==b) == true" << endl;
    };
    if (somebool) {
    	cout << "(somebool) == true" << endl;
    };
    somebool would be false because a != b. That means there will be no ouput from this example code unless you set a=b.

  11. #11
    Registered User Joe100's Avatar
    Join Date
    Jul 2003
    Posts
    63
    hmmmmmm ok i get it now thnxs everyone

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing params between managed c++ and unmanaged c++
    By cechen in forum C++ Programming
    Replies: 11
    Last Post: 02-03-2009, 08:46 AM
  2. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 08:05 AM
  3. DirectInput help
    By Muphin in forum Game Programming
    Replies: 2
    Last Post: 09-10-2005, 12:52 PM
  4. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 05:25 AM
  5. Need Help With an RPG Style Game
    By JayDog in forum Game Programming
    Replies: 6
    Last Post: 03-30-2003, 08:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21