Gets four ages from user, displays them - C++ Data Type

C++ examples for Data Type:Array

Description

Gets four ages from user, displays them

Demo Code

#include <iostream>
using namespace std;
int main()/*from w  w  w  .ja  va2  s . c om*/
{
   int age[4];                     //array 'age' of 4 ints
   for(int j=0; j<4; j++)          //get 4 ages
   {
      cout << "Enter an age: ";
      cin >> age[j];               //access array element
   }
   for(int j=0; j<4; j++)              //display 4 ages
      cout << "You entered " << age[j] << endl;
   return 0;
}

Result


Related Tutorials