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

HW4_3 Write a math drill program as a MATLAB script M-file. The program should d

ID: 441917 • Letter: H

Question

HW4_3 Write a math drill program as a MATLAB script M-file. The program should display a randomly generated addition problem to the screen, and use the MATLAB input command to receive the user's response. Continue to prompt the user until the correct answer is given, displaying the problem again. The addition problems should use numbers from 1 to 99 (use built-in function randi). Use fprintf to show the problem to the screen, and to display appropriate messages for correct and incorrect answers.

Explanation / Answer

% please rate and flag any one that copies answer


num=randi(99,1,2);

correct = num(1) +num(2);

answer= correct+1;

while answer~=correct
fprintf('%d + %d = ',num(1),num(2));
answer=input('');

if answer~=correct
fprintf('Your answer is wrong. Try again. ');
else
fprintf('Your answer is correct! Great job! ');
end
end