I just tried for like 15 minutes to make this work, and I see why you're having trouble :/
The problem you're running into is that when the user inputs a character instead of an integer, since you defined nArray as an integer and it therefore interprets the character as an integer.
You need to figure out a way to make another variable, lets call this one
char charcheck;
, and set it equal to the same value that the user inputs. In your if statement, you need to check if charcheck is between 'a' and 'z' or 'A' and 'Z'. If it is not, then the user did not input a character.
Alternatively, you can use the function isalpha to check if charchek is either an upper or lower case letter. isalpha uses both islower (checks for lower case) and isupper (checks for upper case) and if either of the two functions returns true, then isalpha returns true.
http://www.cplusplus.com/forum/beginner/136156/
^^^Thread that shows a simple example of how to use a similar isdigit function.^^^
So it would look something like this:
1 2 3 4 5 6 7 8 9 10 11 12
|
cin >> array[i], charcheck;
//You need these two to prevent getInput from looping all
//the way through (at least in my environment). I can explain if needed.
cin.clear();
cin.sync();
if ( isalpha(charcheck))
{
cout << "Hello world!" << endl;
}
|
Since Hello World will now execute anytime the user inputs a character, you can write whatever code necessary to get the program to stop.
Anyone feel free to correct me if I'm giving any misinformation.