I'm trying to write a progam that;
Contains a function called sumN() which takes an int n as an argument and returns an int which is the sum of all integers between 1 and n.
In the main() asks the user:
How many values (s)he wants to enter (maximum 50);
Asks for the values and stores them into an array int a[].
Prints to the console sumN(a) for all the elements of a[] that have been entered by the user.
I've gotten this far and when I try to run it, it doesn't work it just says;
in function 'int main()':
error: invalid types 'double[int]' for array subscript. (on line 29)
Here's my code;
#include <iostream>
using namespace std;
int main()
{
double array, set[50];
int size, t, value ;
cout << "How many values do you wish to enter?\n";
cin >> size;
while (size>50)
{
cout << "Sorry, that was above 50" << endl;
cout << "How many values do you wish to enter?\n";
cin >> size;
}
cout << "Enter the values:\n";
for (value=0; value<size; value++)
cin >> set[value];
double SumN(double *array, int size);{
double total = 0;
int i;
for(i = 0; i < size; ++i)
total += *array[i];
return total;}
cout << "Here are your values:\n";
for (t=0; t<size; t++)
cout << set[t] << "\n";
return 0;
}
Could someone please tell me where i'm going wrong as soon as possible?
Thanks :)