Hello everyone!
I am new to this programming world.
I recently wrote a program that prints the sum of the series 1 + 1/2 + 1/3 +...+1/n.
It works perfectly for integers, but how do i get it to say display an error message when someone enters a floating point number.
Right now my program treats 12.5 as 12 and prints the output.
If you are cin>>ing into a int, it will stop at the radix point as that isn't a valid number. You would have to read all the data in as, say, a string, then check to see if there are any invalid characters. You could also read the data then check to see if there is anything other than a newline left, and if so, complain.