Read user input and store it into an array - C++ Language Basics

C++ examples for Language Basics:Console

Description

Read user input and store it into an array

Demo Code

#include <iostream>
using namespace std;
int main()//from  w w w  .  java 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;
}

Result


Related Tutorials