Question: I have a recursive power function my instructions are If user enters non integers, then catch the exception and prompt again, how do i do

I have a recursive power function my instructions are If user enters non integers, then catch the exception and prompt again, how do i do this in the read function from main?

int power(int x, int y){ // recursive power funtion reads two int values if(y>= 0){ if (y==0) return 1; else if (y==1) return x; else return x * power(x,y-1); } else{ return 1/power(x,abs(y)); } }

int main(){ bool success=false; do { try { // read the input values, throw if non int read(); success=true; } catch(...) { // catching all types of exceptions cout << "error in data, try again" << endl << endl; } } while (!success); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!