Clearly, Your approach to read multiple numbers will need a different implementation.
Using cin >> num
reads a single integer & press Enter to allow the buffer to be saved as int in num
.So you will have to press Enter for every number.
But isdigit(num)
fails and kills the while loop. Infact , isdigit
is poorly used.
Why would you want to check int
is a number or not.
isdigit
takes a char type converts to int & find it falls in ASCII range of digits 48 to 57 ( 0,... 9 )
Proper use of isdigit
is
char ch1 = '5';
char ch2 = 'a';
isdigit (ch1) // true
isdigit (ch2) // false
Remove isdigit () check on int which is pointless.
Now that the while loop depends only on cin>>num
, you don't have any termination condition.
Possible approach would be to read multiple numbers could be read space delimited integers and convert into array , if the list of numbers are small enough.
Otherwise , read from File Stream or change the design of reading multiple numbers which relies on single enter to be pressed.