Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (anonymous):

0

OpenStudy (anonymous):

You only want to add one value to sum each loop and you haven't use done to end loop. I see 2 options if you follow the instructions that i has to be incremented before use. I didn't test them but think I didn't miss anything. Option 1 void setup() { done=0; //to make sure it is false sum=0; i=0; } void loop() { i++; sum=sum+data[i-1]; if (i==10) done=1; } Option 2 void setup() { done=0; //to make sure it is false sum=0; i=-1; //start i at -1 to avoid subtraction in indexing } void loop() { i++; sum=sum+data[i]; //index changed to just i if (i==9) done=1; //check changed to 9 }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!