bat78 wrote:It work only with 0+length, while length is 1000.
It also works without the +0 before length. It sounds like you think you need to cast it with the +0.
bat78 wrote: am wondering if that might be made with strings like length[0] = 0; length[1] = 1000; length[2] = 2000; .. And after that use the exact one for the requested amount.
You wouldn't be using strings for that. You would use an array of integers, but aside from that it would just work.
bat78 wrote: i don't think there is a way to define a variable that will be called only for the "even values" and another one that will be called only for the "odd values" . The only way i mind is: if (length == 1 || length == 3|| length == 5) ... but that wont define all odds.
A variable can only hold one value at a time, it wouldn't make sense any other way. So naturally you can't declare a value that holds all even numbers, what value would it give when used? You can however check if a number is even or not. Instead of that if statement, use this.
- Code: Select all
if(length%2==1) // odd
{
//
}
The modulus operator will return the remainder, so if you use var%2, it will return 0 when even, and 1 when odd.