Work with Boolean Operators
So I've been working a bit, with an Else If statement and some boolean operators. Even though I've managed to get it 100% working, I'm not sure if I did anything sloppy, or if there is a more effective way of doing it. If anyone can take a look over my code and let me know, I'd really appreciate it.
Code:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int age; //declaring our integer :O :O :O :O
char test; //Variable containing ONE character.
/* Comparisons evaluate out to a 0 or a 1 depending on whether
its true or false. 0 = false, and 1 = true.
Example: cout<< ( 2 == 1 ); evaluates to a 0
*/
/* Not Operator:
Not operator accepts one input, if its true then it returns false
if its false it returns true. Not (any number != 0 = 0)
Is written as (!)
*/
/* And operator:
Returns true if both inputs are true (1), otherwise returns false (0).
Written as &&. Evaluated before Or Operator.
*/
/* Or Operator:
If either or borth of values are true, then it returns true.
Otherwise returning false (0). Written as ||. Evaluated after And
*/
cout<<"Please input your age: "; // << for output
cin>> age; // >> for input
cin.ignore(); //Ignore enter.
if (!(age == 100)) { // (!100) { //start block
//If age < 100 then run the code!
cout<<"You're not 100 years old!!\n";
}
else if (age == 100) {
cout<<"You're 100 years old!\n";
}
cin.get(); //Pause the program until enter is pressed.
}