C++ cin Read user input and store it into an array

Description

C++ cin Read user input and store it into an array

#include <iostream>
using namespace std;
int main()/* ww w .ja  va 2  s  . c o m*/
{
   const int MAXTEMPS = 5;
   int i, temp[MAXTEMPS];
   for (i = 0; i < MAXTEMPS; i++)   // Enter the temperatures
   {
      cout << "Enter a temperature: ";
      cin  >> temp[i];
   }
   cout << endl;
   for (i = 0; i < MAXTEMPS; i++)   // Print the temperatures
      cout << "temperature " << i << " is " << temp[i] << endl;
   return 0;
}



PreviousNext

Related