How to store 2 elements in one array

How do I receive two numbers from the keyboard, save them in an array of two element?
Hello tidematic,

If I understand you correctly you could use:

 
std::cin >> arrayName[0] >> arrayName[1];


Or you could input to two variables and then set the array elements equal to these variables:

1
2
3
4
5
6
7
int num1{};
int num2{};

std::cin >> num1 >> num2;

arrayName[0] = num1;
array[1] = num2;


If you have something else in mind then you will need to explain your self better.

Hope that helps,

Andy
I recommend reading this first. It explains the basics of arrays really well.
http://www.cplusplus.com/doc/tutorial/arrays/
I meant how would I save 2 integers in one array?
Read SamuelAdam's link. Handy Andy showed you how.
But in case it isn't clear, you can declare an array like this:
int arrayName[2]; // array that can hold 2 ints
Last edited on
Topic archived. No new replies allowed.