Created
November 12, 2014 12:07
-
-
Save pbalduino/5c39a16ed1b88788bf5d to your computer and use it in GitHub Desktop.
Cálculo de média usando IFs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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