Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

Finding and scheduling appointments with new prospective clients.

Answered: 1 week ago