Hi again!

I have these four different if-then that I hope someone could help me with.

``````int i, j;
cin>> i>> j;
if (condition) (
court << "The condition is true!" <<endl;
)``````

Create conditions so that the condition is true if
a) j is not more than 5 numbers from i.
b) j is within a range of + i.
c) is 1 or 1
and j have the same sign as i. (0 positive)
d) is even and j is odd and less than i.

a)

``````int i, j;
cin>> i>> j;
if (j>i+5) {
court << "The condition is true!" <<endl;``````

b)

``````int i, j;
cin>> i>> j;
if (j==i, i+) {
court << "The condition is true!" <<endl;``````

c)

``````int i, j;
cin>> i>> j;
if (j==1, i==1) [
court << "The condition is true!" <<endl;``````

d)

``````int i, j;
cin>> i>> j;
if (i%2 ==0 && jtal%1 ==0 && j<i) {
court << "The condition is true!" <<endl;``````

Can anyone help me to fix these if-then's :/

Edited by Nick Evan: Added code-tags

3
Contributors
4
Replies
6
Views
8 Years
Discussion Span
Last Post by foxmulder

a) j is not more than 5 numbers from i.
if (j>i+5) {
Here you should use more brackets. Like (j>(i+5)) It look better.

b) j is within a range of + i.
I think that this was as withing range + i, is like between 0 and i
but also can be like not further as i+i and not less then i-i.

c)
|| is equivalent of OR
&& is equivalent of AND
The condition definition look as bad formulated.
and j have the same sign as i. (0 positive) :
this look like (i>0,y>0) and at the same this can be also true (i<0,y<0)

Anyway pay attention to the brackets. They are very important for you conditions and algorithmus because then the CPU can decide better what you need. Like (2*2-3) is without bracket like ((2*2)-3)=1 . But the priority of operation can be also like (2*(2-3))=-2 which is not the same as previous part.
Also look on AND and OR for conditions.
http://www.cppreference.com/wiki/operator_precedence

`court` is not the same as `cout` . The difference between them is that one is a C++ command and the other one isn't :)
Also: you can't use all kinds of brackets mixed with another ( () [] {} ) . Each bracket has its own purpose, learn them.

`court` is not the same as `cout` . The difference between them is that one is a C++ command and the other one isn't :)
Also: you can't use all kinds of brackets mixed with another ( () [] {} ) . Each bracket has its own purpose, learn them.

It is quite visible that the guy has copied partion of the code and edited the conditions. Or just what someone has told him that there should be. Anyway this looks very like: I gave you something, now fix it for me to be working.

Hi again!

Yes I copied the code that I wrote from Word because I dont have a compiler for now, I am downloading the free version of Visual Studio and hope it will be done soon, I dont like to write this in notepad :(

Thanks for the help, It all became much more clearer now!

Thanks again!