Contoh Program C# if else if menentukan predikat suatu nilai
using System;
using System.Windows.Forms;
namespace Ifstatment
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonCek_Click(object sender, EventArgs e)
{
int nilai;
nilai = Convert.ToInt16(textBoxNilai.Text);
if ((nilai >= 80) && (nilai <= 100))
{
MessageBox.Show("Nilai A");
}
else if ((nilai >= 70) && (nilai <= 80))
{
MessageBox.Show("Nilai B");
}
else if ((nilai >= 60) && (nilai <= 70))
{
MessageBox.Show("Nilai C");
}
else if ((nilai >= 45) && (nilai <= 60))
{
MessageBox.Show("Nilai D");
}
else
{
MessageBox.Show("Nilai E");
}
}
}
}
using System;
using System.Windows.Forms;
namespace Ifstatment
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonCek_Click(object sender, EventArgs e)
{
int nilai;
nilai = Convert.ToInt16(textBoxNilai.Text);
if ((nilai >= 80) && (nilai <= 100))
{
MessageBox.Show("Nilai A");
}
else if ((nilai >= 70) && (nilai <= 80))
{
MessageBox.Show("Nilai B");
}
else if ((nilai >= 60) && (nilai <= 70))
{
MessageBox.Show("Nilai C");
}
else if ((nilai >= 45) && (nilai <= 60))
{
MessageBox.Show("Nilai D");
}
else
{
MessageBox.Show("Nilai E");
}
}
}
}