Hi,
This is my first post here at DaniWeb. I've been using it as a resource through out my assignments. I am truly eager to learn C++, but I've gotten stuck.
All I am trying to do is average an array of numbers, but I haven't been able to even sum date correctly yet, so I'm taking baby steps.
Here's what I have:
#include <iostream>
#include <stdlib.h>
int sum(int x[], int dim)
{ int ans=0;
for (int i=0; i< dim; i++)
ans += x[i];
return ans;
}
int main(int argc, char *argv[])
{ int x = argc-1;
int a = argv[x];
int arr[1000];
std::cout << "total = " << sum(arr, a) << std::endl;
return 0;
}
and I'm not even sure if it works because I am receiving this error, which I thought I could fix with "atoi"
error: invalid conversion from ‘char*’ to ‘int’
Any help is greatly appreciated. Thanks