That's probably because you're using: cin.get().
cin.get()
only obtains one character from the input stream.
What this means in practice is that if you had entered 1
at the prompt, that value would be stored as a character and not as a double value (which is what you really want).
And, given the ASCII representation of the character 1
being equal to 49 in decimal notation, that means that your input will be interpreted as 49
- which is syntactically correct, but conceptually wrong - hence your results.
More than likely you'll want more than that - you'll want all of your input to be stored correctly. Hence, in this case, it's best to use cin
as follows:
cin >> radius;
Plus, a possible caveat of usage of cin
like this is that it automatically skips whitespace - which is arguably good depending on its usage. Relative to your previous usage of cin
(cin.get()
) could cause more problems than its worth with the intentional or accidental usage of whitespace. So, in this case, it is arguably better to use streams as suggested above, to parse input.
Another option is to use the standard C library input to get input (if you don't like dealing with streams - and there is debate regarding streams usage in C++ vs C-style IO):
http://www.cplusplus.com/reference/cstdio/scanf/