C++ || Snippet – How To Input Numbers Into An Integer Array & Display Its Contents Back To User

Print Friendly, PDF & Email

This snippet demonstrates how to place numbers into an integer array. It also shows how to display the contents of the array back to the user via cout.

REQUIRED KNOWLEDGE FOR THIS SNIPPET

Integer Arrays
For Loops
Constants

NOTE: On some compilers, you may have to add #include < cstdlib> in order for the code to compile.


QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Once compiled, you should get this as your output

How many items do you want to place into the array?: 5
Enter item #1 : 45

Enter item #2 : 7

Enter item #3 : 34

Enter item #4 : 8

Enter item #5 : 2
The current items inside the array are:
Item #1 : 45
Item #2 : 7
Item #3 : 34
Item #4 : 8
Item #5 : 2

Was this article helpful?
👍 YesNo

Leave a Reply