Hi everyone,
I was trying to find the sum of an array of numbers. but when i tried calculating it using the code below, I found the values being continuously increased since the forloop is running. Is there any way that I can get the sum of the numbers in the array other than adding a noLoop function or doing the addition inside void setup?
It would be a great help if someone can help me with this. Many thanks in advance
Cheers, Yousuf.
float sum = 0;
float [] f = {12, 2, 4, 6, 23};
void setup() {
size(600, 600);
smooth();
}
void draw() {
for (int i =0; i<f.length; i++) {
sum +=f[i];
}
println(sum);//// I only wanted to print the first value of sum, which is the total of the numbers listed array of numbers.
}