Ryan wrote:after reading through the scripting for dummies thread twice only for your task (not to tell you the other 50 thousand times i've read through it) and reading a whole array topic on a cprogramming site this is the only thing i can come up with and i'm 100 % sure its wrong:
Code: Select all
int callofduty1 = [21]
for(i = 1; i <=20; i++)
{
iprintln(callofduty1.size); //forwards here
}
for(i = 20; i >=1; i--)
{
iprintln(callofduty1.size); //backwards here
}
The idea is there but wrong execution. The for loops are fine however.
Firstly, with CoDScript you do not need to declare the size of an array or require the 'int'.
You can type simply "arrayName = [];"
That is your array created.
Firstly KS, said to store the numbers inside the array.
To store number in an array we use the following syntax:
arrayName[arrayname.size] = <value>;
to explain what is going on:
Firstly "arrayName" is simply the name we called our array. like a variable, call it what you want.
Secondly, we use the value of "size".
Arrays are an index. Indexes start at ZERO.
So, the current SIZE of the array is ZERO.
arrayName[arrayName.size]
is the same as
arrayName[0]
When we add a value to the array, the array size now becomes 1.
So arrayName[arrayName.size] now equals arrayName[1], etc.
So, we can create an array and populate it using a loop.
Code: Select all
/* Create your array outside the loop */
arrayName = [];
Â
for(i=0;i<21;i++)
{
  arrayName[arrayName.size] = i;
}
You will now have your array of 20 values.
From here, you were asked to print them out.
Your loops were correct, but your prints were slightly wrong.
Instead of printing the size, you print the value.
iprintln(arrayName
);
So, your final code will look like:
Code: Select all
/* Create an array */
callofduty1 = [];
Â
/* Populate your array with values */
for(i=1;i<=20;i++)
{
  callofduty1[callofduty1.size] = i;
}
Â
/* Print the values from 1 to 20 */
for(i = 1; i <=20; i++)
{
  iprintln(callofduty1[i]); //forwards here
}
Â
/* Print the values from 20 to 1 */
for(i = 20; i >=1; i--)
{
  iprintln(callofduty1[i]); //backwards here
}
I urge you to understand the above final piece of code before you try and continue, and do not be confused with Pseudocode, it is just the method of reading code to make it udnerstandable.
When you read your code out loud and make understanding of it, your are essentially thinking Pseudocode.
Also, ignore Megazors exercise, the difficulty level of it was not even amateur let alone beginner...