%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % a program for processing results of a test, which % consists of 2 problems, both evaluated by 0-7 points %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Variant 1 maxpt = 14; % maximum of points k = 1; while (k==1) a = input('points from the first problem: '); b = input('points from the second problem: '); s = a + b; % total sum of points from the test p = s/maxpt*100; % the result expressed in percents p = round(p); % rounding to whole number fprintf('the sum is %d, representing %d%% \n', s, p); if(p>=50) disp('passed'); else disp('failed'); end k = input('Continue (1 = yes, 0 = no) ? '); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Variant 2 maxpt = 14; % maximum of points N = input('how many tests: '); for k = 1:N a = input('points from the first problem: '); b = input('points from the second problem: '); s = a + b; % total sum of points from the test p = s/maxpt*100; % the result expressed in percents p = round(p); % rounding to whole number fprintf('the sum is %d, representing %d%% \n', s, p); switch (floor(p/10)) case 9 disp('A') case 8 disp('B') case 7 disp('C') case 6 disp('D') case 5 disp('E') case {0,1,2,3,4} disp('F') otherwise disp('unexpected result') end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Solving in Command Window using vectors - example: >> t = [ 4 5; 5 2; 3 3] % results for 3 students t = 4 5 5 2 3 3 >> s = sum(t') % sums of points for the 3 students s = 9 7 6 >> p = s/14*100 % percents achieved p = 64.286 50.000 42.857 >> p = round(p) % percents achieved, rounded p = 64 50 43 >> p >= 50 % 1 ... passed, 0 ... failed ans = 1 1 0 ===============================