hey im really really stuck on how to add arrays struggling hard to add some arrays i jus need some examples on how to add simple arrays and work the average out??
You need to use a loop to go through and add the elements to a single variable, then divide by the size. This is the same way you'd work out the average in real life.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Simple Array Average
#include <iostream>
int main()
{
constint SIZE = 10; // You can only create arrays with static integer size.
double grades[SIZE] = { 76, 22, 45, 32, 88, 99, 100, 29, 45, 45};
double average = 0; // Set to 0 to use +=
for (int i = 0; i < SIZE; ++i) // Loop through and add each element.
average += grades[i];
average /= static_cast<double>(SIZE); //Divide by total amount (just like average)
cout << average << endl;
return 0;
}
the problem with your code computer geek is your SIZE evaluation doesn't always work. had they used pointers instead of an array sizeof(array) / sizeof(array[0]) wouldnt give the desired results.
I never heard of or used Gwin or its functions so you'll need to do the proper editing to use the right ones.
1st, change the type of your array to double, as well as the variable average. Second in your for loop use this:
1 2 3 4 5 6
for (counter = 0; counter < 10; ++counter) // You redefined mark here. Error!
{
//Use Gwin.floatwrite or something. AVG IS NOT AN INT
average = average + Mark[counter]; // You need to add each element at its index. Start at 0, go to 9.
// you no longer need counter++; here
}
And Its not an int, so change that, buy make it average/10.0 <-- Defines definite floating point division and not integer division.