Adding Array Elements together

Hello, I'm having trouble getting my array to add its values together. I have a similar program running fine with the exact same equation. I am not so naive as to believe that this means it should run with every program but I'm at a loss as to what to do.
I have pasted my code onto this post. Any advice is accepted.

#include <iostream>
#include <iomanip>
using namespace std;

int main(void)
{
int i=0;
// declare an array and initialize it.
double nums[10]={10.0, 3.0, 8.0, 6.0, 2.0, 11.0, 14.0, 13.0, 10.0, 7.5};

// output it to see what's in them
cout << "These are the values of the 'nums2' array"<<endl;
for (i=0;i<10;i++)
cout << nums[i] << " ";
cout << endl << endl;
//add the last five together
double sum=0;
int a=0;
for (int a=0; a<10;a++);
{
sum+=nums[a];
}
cout<<"this is the sum of the first five values"<<endl;
cout<<sum<<endl;
system("pause");
return 0;
}
Well, when you cout the values, you say the first five values . In the comment above the adding, you say //add the last five together . And in the for-loop where you add, you put a < 10 , so it will run 10 times. So it will add every element.

I believe you wanted just the first 5, so it should be a < 5 .......positions [0], [1], [2], [3], [4] of the array.

But on a different topic, why do you have void as an input to int main?
Use code tags, so I can point exactly the line
for (int a=0; a<10;a++); The problem is the semicolon at the end of the line.
Topic archived. No new replies allowed.