Write a function that prompts the user for a value of an integer n, and returns the value of n. No input arguments are passed to this function. Error-check to make sure that an integer is entered
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:6| Question number:12.6
All Answers
total answers (1)
promptForN.m
function outn = promptForN
% This function prompts the user for n
% It error-checks to make sure n is an integer
% Format of call: promptForN or promptForN()
% Returns an integer entered by the user
inputnum = input('Enter an integer for n: ');
num2 = int32(inputnum);
while num2 ~= inputnum
inputnum = input('Invalid! Enter an integer: ');
num2 = int32(inputnum);
end
outn = inputnum;
end
need an explanation for this answer? contact us directly to get an explanation for this answer