0
is this not wrong?
if the person is 16 then they are not less than 16
10 ответов
+ 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
+ 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;
}
+ 1
The error is in if (!(age>16))
+ 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.
+ 1
Actually, it's only been me and you who posted on this question
+ 1
if(age>=16)
{
// statement
}
0
run the code but instead of using 10 say your age is 16 then this program will say you are less than 16.
0
#include <iostream>
using namespace std;
int main()
{
int age = 16;
if ( !(age > 16) ) {
cout << "Your age is less than 16" << endl;
}
return 0;
}
0
run that code it will say your under 16 when you are 16.
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.