Skip to content

Instantly share code, notes, and snippets.

@pbalduino
Created November 12, 2014 12:07
Show Gist options
  • Select an option

  • Save pbalduino/5c39a16ed1b88788bf5d to your computer and use it in GitHub Desktop.

Select an option

Save pbalduino/5c39a16ed1b88788bf5d to your computer and use it in GitHub Desktop.
Cálculo de média usando IFs
private void btnCalcular_Click(object sender, EventArgs e)
{
// maior
if (txtNota0.Value > txtNota1.Value && txtNota0.Value > txtNota2.Value && txtNota0.Value > txtNota3.Value)
{
lblMaior.Text = txtNota0.Value.ToString();
}
else if (txtNota1.Value > txtNota0.Value && txtNota1.Value > txtNota2.Value && txtNota1.Value > txtNota3.Value)
{
lblMaior.Text = txtNota1.Value.ToString();
}
else if (txtNota2.Value > txtNota0.Value && txtNota2.Value > txtNota1.Value && txtNota2.Value > txtNota3.Value)
{
lblMaior.Text = txtNota2.Value.ToString();
}
else
{
lblMaior.Text = txtNota3.Value.ToString();
}
// menor
if (txtNota0.Value < txtNota1.Value && txtNota0.Value < txtNota2.Value && txtNota0.Value < txtNota3.Value)
{
lblMenor.Text = txtNota0.Value.ToString();
}
if (txtNota1.Value < txtNota0.Value && txtNota1.Value < txtNota2.Value && txtNota1.Value < txtNota3.Value)
{
lblMenor.Text = txtNota1.Value.ToString();
}
if (txtNota2.Value < txtNota0.Value && txtNota2.Value < txtNota1.Value && txtNota2.Value < txtNota3.Value)
{
lblMenor.Text = txtNota2.Value.ToString();
}
if (txtNota3.Value < txtNota0.Value && txtNota3.Value < txtNota1.Value && txtNota3.Value < txtNota2.Value)
{
lblMenor.Text = txtNota3.Value.ToString();
}
// média
decimal media;
media = (txtNota0.Value + txtNota1.Value + txtNota2.Value + txtNota3.Value) / 4;
lblMedia.Text = media.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment