+ 2

I want to take input from user and assign it to an array , how can I do that ?

#include<iostream> #include<conio.h> #include<string> using namespace std; int main() { int x[2],n; cout<<"Enter the numbers \n"; cin>>x; for (n=0;n<3;n++) { x[n]+= 1; cout<<x; } } But this programme is not working , the error is ' cin >>x ' Thanks in advance for helping

27th Jun 2019, 6:20 AM
Foxie
Foxie - avatar
3 ответов
+ 14
There is no use of 'x[n]+=1' statement. Just use cin>>x[n] inside the loop. And if you also want to display the members of the array use another loop with cout<<x[n].
27th Jun 2019, 12:07 PM
Manoj
Manoj - avatar
27th Jun 2019, 6:32 AM
Asmit joy
Asmit joy - avatar