I'm new to this site and have only been learning C++ for a couple months
I'm having a problem with the sum function after the for loop
1)In main, create an array of 10 integer elements. Write a while loop that repeatedly asks the user for an integer to populate the array with values.
2) The sumArray function will take an integer array and an integer (representing how many items are in the array) as input parameters and will sum up all of the values contained in the array. It will return that sum.
#include<iostream>
usingnamespace std;
int sumArray();
int main()
{
constint ARRAY_SIZE = 10;
int numbers[ARRAY_SIZE];
int count = 0;
int num;
cout << "enter a number or -1 to quit \n";
cin >> num;
while (num != -1 && count < ARRAY_SIZE)
{
count++;
numbers[count - 1] = num;
cout << "enter a number or -1 to quit \n";
cin >> num;
}
sumArray();
system("pause");
return 0;
}
int sumArray(10);
int total = 0;
for (count = 0; count < sumArray; count++)
{
total += count;
return << total;
}
#include <iostream>
int sumArray(int [], int);
int main()
{
constint ARRAY_SIZE = 10;
int numbers[ARRAY_SIZE];
int count = 0;
int num;
std::cout << "Enter 10 numbers or -1 to quit\n";
for (int i = 0; i < ARRAY_SIZE; i++)
{
std::cin >> num;
if (num == -1)
{
break;
}
numbers[i] = num;
count++;
}
int sum = sumArray(numbers, count);
std::cout << "\nThe sum is: " << sum << '\n';
}
int sumArray(int arr[], int num_entries)
{
int sum = 0;
for (int i = 0; i < num_entries; i++)
{
sum += arr[i];
}
return sum;
}
Enter 10 numbers or -1 to quit
1
2
3
4
5
6
7
8
9
10
The sum is: 55
Enter 10 numbers or -1 to quit
5
10
15
20
-1
The sum is: 50