Using MATLAB , Write a function posnum that prompts the user to enter a positive number and
Fantastic news! We've Found the answer you've been seeking!
Question:
Using MATLAB,
Write a function posnum that prompts the user to enter a positive number and loops to error-check. It returns the square root of the positive number entered by the user. It calls a subfunction in the loop to print an error message. The subfunction has a persistent variable to count the number of times an error has occurred. Here is an example of calling the function:
>> squarerootvalue = posnum
Enter a positive number: -5
Error #1: Follow instructions!
Does -5.00 look like a positive number to you?
Enter a positive number: -33
Error #2: Follow instructions!
Does -33.00 look like a positive number to you?
Enter a positive number: 4
squarerootvalue = 2
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date: