Professional Documents
Culture Documents
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());
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());
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