You are on page 1of 5

Multiple-Condition Structure

Used to test several conditions in a program

if (condition 1)
{
statement executed if condition 1 is true;
}
else if (condition 2)
{
statement executed if condition 1 is false and condition 2 is true;
}
else
{
statements axacuted if none of the condition is true;
}

int N1;
Console.WriteLine("Enter a number:");
N1 = Convert.ToInt32(Console.ReadLine());

if (N1 < 10)


{
Console.WriteLine("Single digit number.");
}
else if (N1 < 100)
{
Console.WriteLine("Double digit number.");
}
else if (N1 < 1000)
{
Console.WriteLine("Three digit number.");
}
else
{
Console.WriteLine("Number has more than three digits.");
}

Hands-on Activity

int GL;
Console.WriteLine("Enter the grade level of the student: ");
GL = Convert.ToInt32(Console.ReadLine());

Multiple-Condition Structure 1
if (GL == 7)
{
Console.WriteLine("Loyalty award: Bronze");
}
else if (GL == 8)
{
Console.WriteLine("Loyalty award: Silver");
}
else if (GL == 9)
{
Console.WriteLine("Loyalty award: Gold");
}
else if (GL == 10)
{
Console.WriteLine("Loyalty award: Platinum");
}
else
{
Console.WriteLine("Invalid grade level: No available award.");
}

Multiple-Condition Structure 2
Conditionals with operations:

//variables
int num1, num2, ans, choice;

//operations
Console.WriteLine("Calculator");
Console.WriteLine("1 - Addition");
Console.WriteLine("2 - Subtraction");
Console.WriteLine("3 - Multiplication");
Console.WriteLine("4 - Division");
Console.WriteLine("Enter your choice: ");

//inputing operation
choice = Convert.ToInt32(Console.ReadLine());

//inputing the numbers

Multiple-Condition Structure 3
Console.WriteLine("Enter first number: ");
num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter second number: ");
num2 = Convert.ToInt32(Console.ReadLine());

//conditionals
if (choice == 1)
{
ans = num1 + num2;
Console.WriteLine("The answer equals = " + ans);
}

else if (choice == 2)
{
ans = num1 - num2;
Console.WriteLine("The answer equals = " + ans);
}

else if (choice == 3)
{
ans = num1 * num2;
Console.WriteLine("The answer equals = " + ans);
}

else if (choice == 4)
{
ans = num1 / num2;
Console.WriteLine("The answer equals = " + ans);
}

else
{
Console.WriteLine("Invalid");
}

Multiple-Condition Structure 4
Multiple-Condition Structure 5

You might also like