My main problem is that I dont know how to sum values in a vector
That's OK. The Arduino does not do vectors.
a) Write a for loop that sums the ten integer values in the array above .
Are you serious? This is a day-one exercise in any C class. Look at the documentation for the for statement and the array page. No, I'm not going to tell you where. You should KNOW.
b ) Print The largest value in the array. Use System.out.println ( ) to print until
Serial Monitor.
But you will have to avoid numeric overflows as well as buffer overflows and the for-loop has to be done correctly.
If the single elements of your array are 'int' and you don't know about the values you are adding, it would be more safe to use a bigger variable for the result, such like 'long' when adding several 'int' values:
long total=0;
And this would create a buffer overflow if you'd really access your array:
for(i=0; i<= 10; i++);
There is no element with index 10 in your array, so the for-loop compasison has to be:
for(i=0; i<10; i++) ...
In that case the index is increasing from 0 to 9, which is 10 elements.
Besides of that you should not define a do-nothing loop. The syntax of a for-loop is either:
for(...) singleStatement;
So after the round brackets there follows a single statement and a semicolon that finishes the for-loop.
Or the syntax is:
for(...)
{ // curly bracket to start a code block
statement1;
statement2;
...
} // curly bracket to end a code block
And finally the name of the vector elements is Mat_data_vektor and not X. So you better add:
No, not something like that, value goes out of scope when your for loop ends. It is also being redeclared all the time. You also need to watch what you use upper case characters for, C++ is case sensitive. I put it all in setup() so it only executes once.
// Something more like this:
int Mat_data_vektor[10] = {0,1,2,3,4,5,6,7,8,9}; // have something to add up
void setup ()
{
Serial.begin (9600);
int value = 0;
for(int i=0; i<= 10; i++)
{
value += Mat_data_vektor[i]; // equivalent of value = value + Mat_data_vektor[i];
}
Serial.println (value);
}
void loop() {
}
You really need to pay attention to syntax and in particular what this ';' guy does.