I am trying to create the code for a program using a for loop that will add the elements of an array and display "sum = (sum of the array)". I think I am pretty close but I am getting 1 error. Can anyone give me a nudge in the right direction?
Code:#include <iostream> #include <iomanip> using namespace std; int main() { int myarray[] = {3,5,22,4,17,6,14}; for (int i = 0; i < 7; i++) { sum += myarray[i]; } cout << "sum = " << sum; cout << endl; return 0; }