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.
#include <iostream>
#include <algorithm>
usingnamespace 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;
}
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?