Created
November 6, 2014 02:55
-
-
Save ess/9b963ebcb9f40f4d8160 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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