I'm having a problem with my program. I'm able to input all 10 numbers in but when it out puts the sum I get the wrong answer but then when it outputs my average that information is correct. I know it's a simple fix but I can't see it. Can someone please put me in the right direction. I'm beginning to lose my mind.Here is the code
#include <iostream>
using namespace std;
double solution( int a[], int b) //average function
{
int x ;
double sum = 0;
for (x = 0; x < b; x++)
{
sum += a[x]; }
return sum / b; }
int main ()
{
double average=0;
int sum ;
int a [10];
int x ;
for (x = 0; x<10; x++)
{
cout << "Please Enter Your Number :" <<endl;
cin>> a[x];
}
sum=a[x];
cout<<"The sum of your numbers is"<<sum; // shows the sum
average = solution(a,10);
cout << "The Average is "<< average; // shows the average
return (0);
}