top of page
Admin

C# Conditions and IF statements example

Here is a simple console application for letter grade calculation.


using System.Numerics;
Console.WriteLine("MidTerm Grade:");
byte midterm = Convert.ToByte(Console.ReadLine());
Console.WriteLine("Final exam grade:");
byte final = Convert.ToByte(Console.ReadLine());
double average = midterm * 0.4 + final * 0.6;
string grade = "";
if (average < 45)
    grade = "FF";
else if (average >= 45 && average <= 55)
    grade = "DD";
else if (average > 55 && average <= 65)
    grade = "D";
else if (average > 65 && average <= 75)
    grade = "C";
else if (average > 75 && average <= 85)
    grade = "B";
else if (average > 85 && average <= 100)
    grade = "A";
Console.WriteLine("Average {0} and final grade {1}", Math.Round(average, 2), grade);
Console.ReadKey();

1 view0 comments

Recent Posts

See All

コメント

5つ星のうち0と評価されています。
まだ評価がありません

評価を追加
bottom of page