C++: Checking for non-numeric input and assigning to a double
- by Brundle
Here is the code I have at the moment:
char ch;
int sum = 0;
double values[10];
int i = 0;
cin >> ch;
while (!isalpha(ch))
{
values[i] = ch;
sum += values[i];
i++;
cin >> ch;
}
What is happening is that if I enter the value 1, that gets assigned to ch as a char. Now ch is assigning it's value to a double and doing an implicit cast. So it is assigning the ASCII value of '1' to values[i]. I want it to just assign 1 to values[i]. Is there a better way to do this? Or is there something that I'm missing?