Posted: Mon Aug 13, 2007 7:24 pm Post subject: Explain something to me
What does this code mean? Its in C/C++.
Code:
Z = (x>y) ? Y : x;
Just replace the X, Y, and Z with variables.
Here is another bit of that code.
Code:
int soldiers = 5;
int tanks = 10;
int max = (b>1) ? b : a;
int min = (b<a) ? b : a;
cout << "The largest value is: " << max << end1;
cout << "The smallest value is " << min << end1;
An explanation would be nice. _________________
What dosen't kill you, usually does the second time.
(test expression) ? if-true do this : if-false do this
Code:
int soldiers = 5; //int soldiers declaired as 5
int tanks = 10; //tanks declaired as 10
int max = (b>1) ? b : a; // max: if b is greater then 1 then b = max, else 1 = max
int min = (b<a) ? b : a; //min: if b is smaller then a then b = min, else a = min
cout << "The largest value is: " << max << end1; //output of the max, declaired above
cout << "The smallest value is " << min << end1; //output of the min declaired above
// This Code doesnt make sense, but i assume theres more.
u can use this, or u can use the conditional if and else.
they basicly do the same thing except this assigns easier then writing another code.
Edit:
btw, don't forget about C++'s case sensitive
Code:
Z = (x>y) ? Y : x;
should be
Code:
Z = (x>y) ? y : x;
Z has to be upercase when u call it _________________
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum