Always 100
#1

pawn Код:
new payment = (weight > 9 && weight <= 50) ? 100 : (weight > 50 && weight <= 100) ? 150 : (weight > 100 && weight <= 150) ? 200 : (weight > 150 && weight <= 200) ? 250 : 0;
Payment is always 100, even if weight is above 50..
Reply
#2

I've read this http://www.swansontec.com/sopc.html

And if I understand correctly, it 'reads' from right to left? I tried this to test it:
pawn Код:
new payment = (9 < weight && 50 => weight) ? 100 : (50 < weight && 100 => weight) ? 150 : (100 < weight && 150 => weight) ? 200 : (150 < weight && 200 => weight) ? 250 : 0;
But got errors.

I've also tried
pawn Код:
new payment = (weight > 9 && weight <= 50) ? 100 : ((weight > 50 && weight <= 100) ? 150 : ((weight > 100 && weight <= 150) ? 200 : ((weight > 150 && weight <= 200) ? 250 : 0)));
But the same result.
Reply
#3

Have you tried?
pawn Код:
new
    payment
;
if( weight > 9 && weight <= 50 ) payment = 100;
else if( weight > 50 && weight <= 100 ) payment = 150;
else if( weight > 100 && weight <= 150 ) payment = 200;
else if( weight > 150 && weight <= 200 ) payment = 250;
else payment = 0;

// -- OR --

new
    payment
;
switch( weight )
{
    case 10 .. 50: payment = 100;
    case 51 .. 100: payment = 150;
    case 101 .. 150: payment = 200;
    case 151 .. 200: payment = 250;
    default: payment = 0;
}
Reply
#4

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Have you tried?
pawn Код:
new
    payment
;
if( weight > 9 && weight <= 50 ) payment = 100;
else if( weight > 50 && weight <= 100 ) payment = 150;
else if( weight > 100 && weight <= 150 ) payment = 200;
else if( weight > 150 && weight <= 200 ) payment = 250;
else payment = 0;

// -- OR --

new
    payment
;
switch( weight )
{
    case 10 .. 50: payment = 100;
    case 51 .. 100: payment = 150;
    case 101 .. 150: payment = 200;
    case 151 .. 200: payment = 250;
    default: payment = 0;
}
I know how to do it that way. I've never used the ternary operator with nesting.. So I thought i'd try it.
Reply
#5

Yes, but within the language guide it says exactly the same.
Source: http://puu.sh/48ZD6.png
Reply
#6

Quote:
Originally Posted by thefatshizms
Посмотреть сообщение
I know how to do it that way. I've never used the ternary operator with nesting.. So I thought i'd try it.
The reason I posted the above is not because I doubt if you knew it or not. Does it actually work without the ternary operator method?
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
The reason I posted the above is not because I doubt if you knew it or not. Does it actually work without the ternary operator method?
Ah that's probably the problem, ahah. It doesn't work without the ternary (Still 100).

edit: Fixed! It was a stupid mistake..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)