I wrote this simple program today, but I found that cin.get() refuses to work unless there are 2 of them. Any ideas?
#include
u
Variable base has not been initialized.
You can fix it by giving an invalid value to base as:
int base = 1; // 1 is not in the valid range.
while ((base < 2) || (base > 36)){
or
better use a do-while loop as:
int base;
do{
cout << "Base (2-36):" << endl;
cin >> base;
} while ((base < 2) || (base > 36));
The reason why you need the 2nd cin.get() is that, after you read the base value using cin, a \n is left in the buffer. The first call to cin.get() consumes that \n and the 2nd cin.get waits for your input. To avoid this you need to flush the \n from the buffer after cin by calling cin.ignore