Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a MATLAB script (Classic program) that: Prompts it user to enter a valid I

ID: 1995010 • Letter: W

Question

Write a MATLAB script (Classic program) that: Prompts it user to enter a valid Integer literal Reads what the user types(unevaluated) into a string variable. Determine if the string is a valid Integer literal based on the following rules. Consists of only of the following characters: '+', '-', and the digits "0" through V The '+' or '-' character may only appear (once) as the first character Consists of at least 1 character other than the characters: '+' or '-' character. Display what the user entered and the determination to the screen is a reasonable report like format. Please enter a valid Integer literal: +is not a valid Integer literal Please enter a valid Integer:2 2 is a valid Integer literal Please enter a valid Integer literal: -42 -42 is a valid Integer literal

Explanation / Answer

MATLAB code

x=input('Please enter a valid Integer literal :','s');
if x=='+' | x=='-'
ans=[x ' is not a valid integer literal'];
disp(ans)
elseif isinteger(x)==0
ans=[x ' is a valid integer literal'];
disp(ans)
end

output:

Please enter a valid Integer literal :+
+ is not a valid integer literal


Please enter a valid Integer literal :2
2 is a valid integer literal


Please enter a valid Integer literal :-42
-42 is a valid integer literal

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote