#Help fixing my code

14 messages · Page 1 of 1 (latest)

chilly zodiacBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

bright magnet
#

In C you can combine expressions

#

A common thing is something like this:

while (i < max)
{
  int a = foo[i++];
  int b = foo[i++];
  ...
}

Here int a = foo[i++]; is the same as doing this:

int a = foo[i];
i++;
#

We can also do it the other way, first update:

#
int a = foo[++i];
#

This is the same as:

i++;
int a = foo[i];
#

Now we can do this inside a complex expression, like this:

int a = ++i < 10 ? j++ : ++k;
#

The above can be rewritten like this:

#
++i;
int a;
if (i < 10)
{
   a = j;
   j++;
}
else
{
   k++;
   a = k;
}
#

Once you understand the above you can understand how you can both combine < and -- inside of () into an expression.

rotund musk
#

im sorry but im extremely confused. this is all extremely new to me.

#

I need to use his template which is "while ( ___ )"

#

but didnt I do it here? " while (i > countdown) "

#

"The decrement operator was to be used inside the condition of your while loop."
how do i fix this as well?