+ 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
3 Answers
+ 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].
+ 4
Here is your solution...
https://stackoverflow.com/questions/48055746/using-for-loop-for-user-input-in-an-array