All Type Coding

Search Here

How do I find enter the marks of a student in five subjects and then find his grand total ,average and his grade in c#.?

using System;

class abc
{
    float hindi, eng, sci, maths, sst, total, avg;
    public void fun()
    {
        Console.WriteLine("Program to find the grade and total marks of a student");

        Console.WriteLine("Enter the marks of hindi out of 100");
        hindi = Convert.ToSingle(Console.ReadLine());

        Console.WriteLine("Enter the marks of english out of 100");
        eng = Convert.ToSingle(Console.ReadLine());

        Console.WriteLine("Enter the marks of science out of 100");
        sci = Convert.ToSingle(Console.ReadLine());

        Console.WriteLine("Enter the marks of maths out of 100");
        maths = Convert.ToSingle(Console.ReadLine());

        Console.WriteLine("Enter the marks of social studies out of 100");
        sst = Convert.ToSingle(Console.ReadLine());

        total = hindi + eng + sci + maths + sst;
        Console.WriteLine("His grand total is : " + total + " out of 500");

        avg = (hindi + eng + sci + maths + sst) / 5;
        Console.WriteLine("His average marks is : " + avg);

        if (avg >= 80)
        {
            Console.WriteLine("Grade is 'A' ");
        }
        else if (avg >= 60 && avg < 80)
        {
            Console.WriteLine("Grade is 'B' ");
        }
        else if (avg >= 50 && avg < 60)
        {
            Console.WriteLine("Grade is 'C' ");
        }
        else if (avg >= 40 && avg < 50)
        {
            Console.WriteLine("Grade is 'D' ");
        }
        else
        {
            Console.WriteLine("Grade is 'E' ");
        }
        Console.ReadKey();

    }
}
class grade
{
    public static void Main(string[] args)
    {
        abc a1 = new abc();
        a1.fun();
    }

}
Output:


No comments :

Post a Comment