im writing a program with a function power() thats asks the user for a number, and the number of times it needs to be multiplied by itself, with a default of squaring the number if the argument is ommited. but if i dont enter a value the program stalls and doesnt execute. my question is, how to get cin to accept nothing when hitting enter and continue with the rest of the statements?
heres what i have in main:
once this code hits 'cin >> times' and i just hit enter with no value, the program stalls. thanks in advance.Code:int main() { double number; int times; cout << "Enter in a number: "; cin >> number; cout << "Enter the times to be multiplied by itself: "; cin >> times; cout << "Result = " << power(number, times) << endl; return 0; }



LinkBack URL
About LinkBacks


