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

前端 未结 4 1754
滥情空心
滥情空心 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:12

    string stream should be able to do the conversion for you. A pass through atoi could also get the job done.

提交回复
热议问题