Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

C++ boolean types ....

Is anyone here who really can explain me how “boolean” work?
And please give me some example if you can!!!
Thanks!
ThePolitician
Code
if (this.thread == a_joke)
{
  return true;
}

?
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
A Boolean, from my understanding is just a true or false. Yes or no. 0 or 1

Simple as that. it's used to determine if something is or isn't.
if (5+5==10){
 return true;
} else {
 return false;
}

// if used productively then its used like this...

int main(){
int age;
bool isAble = false // able to drive initially false
cout << "Age :" << endl;
cin age;
if (age >= 17){
isAble = true;
} else if (age < 17){
isAble = false;
}

while(isAble){
cout << endl << "user is able to drive";
}

while(!isAble){
cout << endl << "user unable to drive";
}
return 0;
}
(Nov 20, 2018 10:15 AM)iTHX Wrote:  if (5+5==10){
 return true;
} else {
 return false;
}

// if used productively then its used like this...

int main(){
int age;
bool isAble = false // able to drive initially false
cout << "Age :" << endl;
cin age;
if (age >= 17){
isAble = true;
} else if (age < 17){
isAble = false;
}

while(isAble){
cout << endl << "user is able to drive";
}

while(!isAble){
cout << endl << "user unable to drive";
}
return 0;
}

I don't see how that is productive because the expressions are bools too. Not sure what the while loops are for, they won't terminate by themselves. You also over-complicated a simple if-else statement.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
either true or false nothing more
Remember that despite being a binary value, it is still of the size of a byte because it needs to be allocated in the memory
(Nov 20, 2018 10:22 AM)0xDEAD10CC Wrote:  I don't see how that is productive because the expressions are bools too. Not sure what the while loops are for, they won't terminate by themselves. You also over-complicated a simple if-else statement.

i understand your point, i was just trying to find an excuse to use them in a basic, understandable program. i can do much better than this


Possibly Related Threads...
Thread / Author Replies Views Last Post
by HackersApr 29, 2024 05:37 AM 27 475 Apr 29, 2024 05:37 AM
Last Post: nucleo_type09
[.NET] by MankOct 4, 2020 07:53 PM 3 147 Oct 4, 2020 07:53 PM
Last Post: Mank
[.NET] by Mr ReddingtonSep 2, 2016 02:41 PM 6 158 Sep 2, 2016 02:41 PM
Last Post: Mr Reddington