Basic Sorting Program

Hi!
I'm a relatively new to C++, trying to write this program off-by-heart without referring to my books, but I've run into a problem. I want the user to be able to input numbers into the array, aNumbers. However, it doesn't like my code and it takes, for example, the number 10 as two numbers, 1 and 0. How can I create a "gap" so to speak for the input of the numbers in the 'for' loop.

I understand this is probably a really crappy way of doing this, but I'm just trying stuff out. Any ideas why it's not working? I have a feeling but I can't quite pin down the problem.

Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int nNumbers;

	cout << "How Many Numbers Would You Like to Sort? (Up to 6)\n";
	cin >> nNumbers;

	if (nNumbers == 1)
	{
		cout << "Please Enter More Than One Number!\n";
		cout << "How Many Numbers Would You Like to Sort? (Up to 6)\n";
		cin >> nNumbers;
	}
	
	cout << "Enter " << nNumbers << " Numbers for sorting: \n";
	
	if (nNumbers == 2)
	{
		char aNumbers[2];

		for (int i = 0; i < 2; i++)
		{
			cin >> aNumbers[i];
		}
	
		cout << "You Have Entered These Numbers: \n";
		cout << aNumbers[0] << ", " << aNumbers[1] << ".";
	}


	system("Pause");
	return 0;
}
your aNumbers array should be declared as an integer array not a char array
Yep that worked! Thanks.

I originally had as an int array, but the cin >> aNumbers; spat out an error about operators. Changing it to char fixed that. But now as int again it works?

Do you know why?

THANKS!
Topic archived. No new replies allowed.