Checking for non-numeric input and assigning to a double in C++?

前端 未结 4 1741
滥情空心
滥情空心 2021-01-17 04:27

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; 
          


        
4条回答
  •  孤街浪徒
    2021-01-17 05:01

    Read the entire number as a string, and the convert the whole thing to a double by using the strtod function or some other C++-specific means.

提交回复
热议问题