0% found this document useful (0 votes)
3 views2 pages

Ex 4 Roll4

The document outlines a C# program that demonstrates the use of if-else ladder and switch statement to evaluate grades. It prompts the user to enter a grade and provides feedback based on the input using both control structures. The program handles valid grades (A, B, C, D, F) and includes a response for invalid inputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Ex 4 Roll4

The document outlines a C# program that demonstrates the use of if-else ladder and switch statement to evaluate grades. It prompts the user to enter a grade and provides feedback based on the input using both control structures. The program handles valid grades (A, B, C, D, F) and includes a response for invalid inputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Marwadi University

Faculty of Diploma Studies


Department of Information and Communication Technology
Subject:.NET Aim: Write a C# code to demonstrate the concept of if else
(09CT1502) ladder andswitch statement.
Experiment No: 4 Date: Enrolment No:92200957012

using System;

class Program
{
static void Main(string[] args)
{

Console.Write("Enter a grade (A, B, C, D, F): ");


char grade = Convert.ToChar(Console.ReadLine().ToUpper());

Console.WriteLine("\nUsing if-else ladder:");


if (grade == 'A')
{
Console.WriteLine("Excellent!");
}
else if (grade == 'B')
{
Console.WriteLine("Good!");
}
else if (grade == 'C')
{
Console.WriteLine("Fair!");
}
else if (grade == 'D')
{
Console.WriteLine("Needs Improvement!");
}
else if (grade == 'F')
{
Console.WriteLine("Fail.");
}
else
{
Console.WriteLine("Invalid grade entered.");
}

// Demonstrating switch statement


Console.WriteLine("\nUsing switch statement:");
switch (grade)
{
case 'A':
Console.WriteLine("Excellent!");
break;
case 'B':
Console.WriteLine("Good!");
break;
case 'C':
Console.WriteLine("Fair!");
break;
case 'D':
Console.WriteLine("Needs Improvement!");
break;
case 'F':
Console.WriteLine("Fail.");
break;
default:
Console.WriteLine("Invalid grade entered.");
break;
}
}
}
Output:

You might also like