switch, menu functions
이전 댓글 표시
so one of the hw problems i'm working on has thrown me into a big puzzle, i'm not sure whats going on. the question ask you to imprt a text file (which i did ) which are grades for few students for a quiz and 3 exams. it says that make a function to determine what a student needs to make in the final in order to have an A B C D in class. It says give the user a menu to ask them what grade they want, depending on there choice use switch function to determine what function to use
here's what i have so far
(function)
function [ finalA ] = grades_finalA( q1,e1, e2, e3 )
finalA=(90-q1*.10-e1*.20-e2*.20-e3*.20)/.30;
end
function [ finalB ] = grades_finalB( q1,e1, e2, e3 )
finalB=(80-q1*.10-e1*.20-e2*.20-e3*.20)/.30;
end
function [ finalC ] = grades_finalC( q1,e1, e2, e3 )
finalC=(70-q1*.10-e1*.20-e2*.20-e3*.20)/.30;
end
function [ finalD ] = grades_finalD( q1,e1, e2, e3 )
finalD=(60-q1*.10-e1*.20-e2*.20-e3*.20)/.30;
end
%%script
clc
clear all
load grades2.txt
grades2(:,2)=q1;
grades2(:,3)=e1;
grades2(:,4)=e2;
grades2(:,5)=e3;
pick=menu('Grades','A','B','C','D')
grades2(:,2)=q1;
grades2(:,3)=e1;
grades2(:,4)=e2;
grades2(:,5)=e3;
switch pick
case 1
final=grades_finalA(q1,e1,e2,e3)
case 2
final=grades_finalB(q1,e1,e2,e3)
case 3
final=grades_finalB(q1,e1,e2,e3)
case 4
final=grades_finalB(q1,e1,e2,e3)
end
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!