Totals eight input int values from the user. - C++ File Stream

C++ examples for File Stream:cin

Description

Totals eight input int values from the user.

Demo Code

#include <iostream>
using namespace std;
const int NUM = 8;
void main()//  w ww.  ja  v  a 2  s. c  o m
{
   int nums[NUM];
   int total = 0;      // Holds total of user's eight numbers.
   int ctr;
   for (ctr=0; ctr<NUM; ctr++)
   {
      cout << "Please enter the next number...";
      cin >> nums[ctr];
      total += nums[ctr];
   }
   cout << "The total of the numbers is " << total << "\n";
   return;
}

Result


Related Tutorials