I'm working on an assignment for class and am having a bit of a hard time putting it together. I had just started learning arrays and am not sure exactly how to get user input in the array.
Here is the assignment prompt: Create a program that inputs up to 100 integers (space separated!) and outputs their sum. For example:
1 2 3 4 5 6 7 8 9 10 55
This is what I have so far (edit because I forgot to change comments):
#include <iostream>
using namespace std;
int addNum(int n);
int main() {
int n;
// prompt user to input numbers
cout << "Please enter in values to add together: ";
cin >> n;
cout << addNum(n);
// pause and exit
getchar();
getchar();
return 0;
}
// function
int addNum(int n) {
int arr[99] = {};
int sum = 0;
for (int i = 0; i < n; i++) {
sum = sum + arr[i];
}
return sum;
}