User Input in Array in C++

User Input in Array in C++ programming is a collection of the data items taken from the user, which is accessed by using common name. we use two types of arrays in C++ programming one and two-dimensional array.

Program User Entered Values in Array Printing

Program

#include<iostream.h>
#include<conio.h>
void main()
{
cout<<"Please Enter Integers"<<endl;
int arr[5]; //'arr' is name of Array and 5 is length.
for(int i = 0; i < 5; i++)
{
cin>>arr[i]; //user entered values storing in 'arr' Array.
}
cout<<"Entered Values"<<endl;
for(int j = 0; j < 5; j++)
{
cout<<arr[j]<<endl; //printing 'arr' Array Elements.
}
getch();
}
Output
Please Enter Integers
13
67
5
44
2
Entered Values
13
67
5
44
2

Program User Enter Strings in Array Printing

Program

#include<iostream.h>
#include<conio.h>
#include<string>
void main()
{
cout<<"Please Enter Names"<<endl;
string arr[4]; //'arr' is name of Array and 4 is length.
for(int i = 0; i < 4; i++)
{
cin>>arr[i]; //user entered values storing in 'arr' Array.
}
cout<<"Entered Names"<<endl;
for(int j = 0; j < 4; j++)
{
cout<<arr[j]<<endl; //printing 'arr' Array Elements.
}
getch();
}
Output
Please Enter Names
Bilal
Khan
PK
Earth
Entered Names
Bilal
Khan
PK
Earth

Program User Enter Name in Array Printing

Program

#include<iostream.h>
#include<conio.h>
void main()
{
cout<<"Please Enter Ur Name"<<endl;
char arr[5]; //'arr' is name of Array and 5 is length.
for(int i = 0; i < 5; i++)
{
cin>>arr[i]; //user entered values storing in 'arr' Array.
}
cout<<"Entered Name"<<endl;
for(int j = 0; j < 5; j++)
{
cout<<arr[j]; //printing 'arr' Array Elements.
}
getch();
}
Output
Please Enter Ur Name
Bilal
Entered Name
Bilal

Program User Enter Values in Arrays Printing
Program

#include<iostream.h>
#include<conio.h>
void main()
{
char name[3]; //this is Arrays.
float price[3];
int pages[3], i;
cout<<"Enter names, prices and no. of pages of 3 books"<<endl;
for(i = 0 ; i <= 2 ; i++)
             //User enter values storing in Arrays.
cin>>name[i]>>price[i]>>pages[i];
cout<<"This is what you entered"<<endl;
for(i = 0 ; i <= 2 ; i++)
cout<<"Name: "<<name[i]<<", Price: "<<price[i]<<", Pages: "<<pages[i]<<endl; //and printing.
getch();
}
Output
Enter names, prices and no. of pages of 3 books
A
100
40
B
160
70
C
250
90
This is what you entered
Name: A, Price: 100, Pages: 40
Name: B, Price: 160, Pages: 70
Name: C, Price: 250, Pages: 90