Syntax
any_loop{
// Based on Array Size
}
//12 is Array Size
for (i = 0; i < 12; i++) {
// Reading User Input sales value Based on index
cin >> sales[i]; //i is index
}
Example Program
/* Read User Input into Array example program In C++ Programming Language
Array Example In C++*/
// Header Files
#include <iostream>
#include<conio.h>
using namespace std;
int main() {
// declaring sales array in C
int sales[12];
int i; // Variable for access sales array index
cout << "Read User Input into Array In C++ Example Program\n";
for (i = 0; i < 12; i++) {
// Reading User Input sales value Based on index
cout << "Enter Value for Position " << i << " : ";
cin >> sales[i];
}
cout << "\n User Input Values\n";
for (i = 0; i < 12; i++) {
// Accessing sales value using for loop
cout << "Position : " << i << " , Sales Value : " << sales[i] << " \n";
}
getch();
return 0;
}
Sample Output
Read User Input into Array In C++ Example Program
Enter Value for Position 0 : 900
Enter Value for Position 1 : 200
Enter Value for Position 2 : 800
Enter Value for Position 3 : 700
Enter Value for Position 4 : 750
Enter Value for Position 5 : 901
Enter Value for Position 6 : 800
Enter Value for Position 7 : 820
Enter Value for Position 8 : 980
Enter Value for Position 9 : 860
Enter Value for Position 10 : 870
Enter Value for Position 11 : 930
User Input Values
Position : 0 , Sales Value : 900
Position : 1 , Sales Value : 200
Position : 2 , Sales Value : 800
Position : 3 , Sales Value : 700
Position : 4 , Sales Value : 750
Position : 5 , Sales Value : 901
Position : 6 , Sales Value : 800
Position : 7 , Sales Value : 820
Position : 8 , Sales Value : 980
Position : 9 , Sales Value : 860
Position : 10 , Sales Value : 870
Position : 11 , Sales Value : 930