C++ Array accumulate each element

Description

C++ Array accumulate each element

#include <iostream>
using namespace std;
int main()/*from   w  w w .jav  a2  s  . c  o  m*/
{
   const int MAXTEMPS = 5;
   int i, temp[MAXTEMPS], total = 0;
   for (i = 0; i < MAXTEMPS; i++)    // enter the temperatures
   {
      cout << "Enter a temperature: ";
      cin  >> temp[i];
   }
   cout << "\nThe total of the temperatures";
   for (i = 0; i < MAXTEMPS; i++)    // display and total the temperatures
   {
      cout << "  " << temp[i];
      total = total + temp[i];
   }
   cout << " is " << total << endl;
   return 0;
}



PreviousNext

Related