In addition, you can format the code in the forum by selecting your code and hitting the formatting code button which looks like this: </>. Formatting code is a good practice to ensure your code is not modified by the Forum markdown processor when it is published plus it makes your code easier to read.
You have declared the array contenitore twice in the first two lines. So delete the first line.
The ‘=’ sign is the assignment operator, it means evaluate what is on the right-hand-side and store it in the variable on the left-hand-side. The data types for both sides must be the same. So
won’t work because contenitore is an array of booleans and the RHS returns a float
replacing it with contenitore[i] = random(100); won’t work because contenitore[i] is a boolean and random(100) returns a float.
As @kfrager points out you can’t have code outside of a function.
I suggest you look at the examples and simple tutorials for Processing so you understand how code is supposed to be organised. In particular look at the tutorial on setup() and draw().
This is your first time here so I will give you a hint on how to get better help.
Statements like
and
are useless because they don’t say what is wrong or what the error is. You need to give much more information on what you expected to happen, what actually happened and details of any error messages.
ok thanks very kind, thanks for the “welcome” possibly today is the first day!
Anyway I didn’t understand much
What should I do to get the correct code?
sorry if I ask you but I need :), I should initialize a boolean type array containing five elements, then assign to each value of the array if it is false or true by establishing it with a ‘for loop’ and at each cycle generate a random from zero to one hundred and if the number was less than 50 then it would be TRUE, otherwise FALSE.
This is what I’m trying to figure out how to do it.
you are very kind, thank you
I am going to assume that this is school work about arrays so I am not going to give you a fully worked answer but help you do it for yourself.
Since there is no graphics we don’t need a draw() method.
The for loop needs to be in a function in this case setup() so the basic code is
// Global variables
// setup function which is executed once when the sketch starts
void setup(){
// All your code will go here
}
In terms of global variables you only need the boolean array and an int for the random number which you have already created so lets add that and some pseudocode for the your code
// Global variables
int randomNum;
boolean[] contenitoreVario = new boolean [5];
// setup function which is executed once when the sketch starts
void setup(){
// pseudocode V V V V V V V V V
// for each element in our array
// get a random number in the range >=0 and < 100 and store it in our variable
// if the number is less than 50
// store TRUE in the current array element
// else
// store FALSE in the current array element
// end if
// end for
// print array
}