Skip to content

Instantly share code, notes, and snippets.

@ess
Created November 6, 2014 02:55
Show Gist options
  • Save ess/9b963ebcb9f40f4d8160 to your computer and use it in GitHub Desktop.
Save ess/9b963ebcb9f40f4d8160 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main() {
const int NUM_ELEMENTS = 8; // Number of elements
int userVals[NUM_ELEMENTS]; // User numbers
int i = 0; // Loop index
int sumVal = 0; // For computing sum
// Prompt user to populate array
cout << "Enter " << NUM_ELEMENTS << " integer values..." << endl;
for (i = 0; i <= NUM_ELEMENTS; ++i) {
cout << "Value: " << endl;
cin >> userVals[i];
}
// Determine sum
sumVal = 0;
for (i = 0; i < NUM_ELEMENTS; ++i) {
sumVal = sumVal + userVals[i];
}
cout << "Sum: " << sumVal << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment