How do I write code that gets scores for 3 exams: Exam1, Exam2, Exam3 as input (via arguments). Prints them (nicely, using fprintf). Finds their average: Avg. Assigns a Grade according to the scale: A if Avg ≥ 90, B for 80 ≤ Avg < 90, and so on, down to F for Avg < 60. Finally, prints the Avg and Grade.

3 件のコメント

John D'Errico
John D'Errico 2018 年 10 月 30 日
What have you tried? If nothing, then why not? After all, it is doing your homework that you will learn. Start writing. Take a shot at it. If you have a problem, then show what you did, and ask for help in how to fix it. Explain what you perceive to be where you are stuck.
Corey Butler
Corey Butler 2018 年 10 月 30 日
Exam1 = input('What is the grade for Exam1? '); Exam2 = input('What is the grade for Exam2? '); Exam3 = input('What is the grade for Exam3? '); fprintf('The grades for three exams are %3.1f , %3.1f , and %3.1f.\n',Exam1,Exam2,Exam3)
E = [Exam1; Exam2; Exam3] Avg = mean(E)
if (Avg >= 90) fprintf('A'); elseif (Avg >= 80 && Avg < 90) fprintf('B'); elseif (Avg >= 70 && Avg < 80) fprintf('C'); elseif (Avg >= 60 && Avg < 70) fprintf('D'); else (Avg < 60) fprintf('F'); end
Corey Butler
Corey Butler 2018 年 10 月 30 日
I need to assign Grade to the letter grades so I can print out both the average and the letter grade.

サインインしてコメントする。

 採用された回答

madhan ravi
madhan ravi 2018 年 10 月 30 日

1 投票

_I need to assign Grade to the letter grades so I can print out both the average and the letter grade._
A1=70. %an example adapt to your needs
A2='C'
formatSpec = 'Average is %d and grade is %s';
fprintf(formatSpec,A1,A2)

2 件のコメント

Corey Butler
Corey Butler 2018 年 10 月 30 日
Oh I used Grade = 'letter' instead of fprintf('letter') and it works. The %s is what I needed. Thanks for help.
madhan ravi
madhan ravi 2018 年 10 月 31 日
Anytime :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で MATLAB についてさらに検索

質問済み:

2018 年 10 月 30 日

コメント済み:

2018 年 10 月 31 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by