Q:

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

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now