0

is this not wrong?

if the person is 16 then they are not less than 16

11th Jun 2018, 5:30 AM
Nicholas Marien
Nicholas Marien - avatar
10 Answers
+ 2
That statement is true. Imagine this code : int age = 16; if(age <16) cout <<"You're not allowed to drive"; else cout <<"You need a driver's license to drive"; The output will be "You need a driver's license to drive", because 16 is not smaller than 16
11th Jun 2018, 5:38 AM
Alexandru Turculet
Alexandru Turculet - avatar
+ 2
// not less than == at least == less than or equal to #include <iostream> using namespace std; int main() { int age = 16; if ( !(age > 16) ) { cout << "Your age is less than or equal to 16" << endl; } return 0; }
11th Jun 2018, 6:17 AM
Hanz
Hanz - avatar
+ 1
The error is in if (!(age>16))
11th Jun 2018, 5:45 AM
Alexandru Turculet
Alexandru Turculet - avatar
+ 1
Basically, what the ! does is invert the value from true to false and from false to true. In your question, you made it seem like you checked age < 16, but for !(age>16) you have 2 possibilities for it to return true. Either age is smaller than 16 or it is equal to 16.
11th Jun 2018, 5:48 AM
Alexandru Turculet
Alexandru Turculet - avatar
+ 1
Actually, it's only been me and you who posted on this question
11th Jun 2018, 5:52 AM
Alexandru Turculet
Alexandru Turculet - avatar
+ 1
if(age>=16) { // statement }
11th Jun 2018, 7:03 AM
Aveek Bhattacharyya
Aveek Bhattacharyya - avatar
0
run the code but instead of using 10 say your age is 16 then this program will say you are less than 16.
11th Jun 2018, 5:42 AM
Nicholas Marien
Nicholas Marien - avatar
0
#include <iostream> using namespace std; int main() { int age = 16; if ( !(age > 16) ) { cout << "Your age is less than 16" << endl; } return 0; }
11th Jun 2018, 5:44 AM
Nicholas Marien
Nicholas Marien - avatar
0
run that code it will say your under 16 when you are 16.
11th Jun 2018, 5:47 AM
Nicholas Marien
Nicholas Marien - avatar
0
sure there are certainly 3 different ways you could change that to make it better code. also I think if you look at the comments there are many people saying the same thing.
11th Jun 2018, 5:51 AM
Nicholas Marien
Nicholas Marien - avatar