+ 4

Can someone help me in this code?

I need to know if something is wrong over here. Also I need to know how to add an input to the array. For example: #include iostream using namespace std; int main() { int wholeZoo[3]; for (int x =0; x < 3; x++) { wholeZoo[x] = {kangaroos, elephants, zebras}; } return 0;}

15th Oct 2017, 3:41 PM
DeltaTick
DeltaTick - avatar
3 Answers
+ 4
The array is an array of integers and there aren't any variables kangaroo, zebra etc declared. Also, you cannot initialize arrays like this. Either you do : int wholeZoo[3]={1,2,3}; //Initializer lists are available only during creation of array. Or for(int i=0;i<3;i++) { wholeZoo[i] = 1+i; //Will do the same as above. // Doing wholeZoo[i]={1,2,3}; is invalid as you cannot assign an array to an int. } And to make an input loop, you do: for(int i=0;i<3;i++) { cin>>wholeZoo[i]; }
15th Oct 2017, 3:59 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 4
Wow, thanks!!!!!!!!!!!!! You now opened my eyes!
15th Oct 2017, 4:02 PM
DeltaTick
DeltaTick - avatar
+ 4
Welcome!
15th Oct 2017, 4:03 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar