Let the user enter their notes in the three text boxes. Calculate the average of these grades and write the result as "Passed" or "Failed".
If any of the boxes is empty, an error message will be given.
If a number less than 0 or greater than 100 is entered in any of the boxes, an error message will be given.
First we need to check if the boxes are empty. If all three boxes are full, we can take numbers into variables. Then we need to see if the numbers are between 0 and 100.
Solution:
if(textBox2.Text=="" || textBox3.Text=="" || textBox4.Text=="")
{
MessageBox.Show("Missing information");
}
else
{
int a = int.Parse(textBox2.Text);
int b = int.Parse(textBox3.Text);
int c = int.Parse(textBox4.Text);
if (a < 0 || a > 100 || b < 0 || b > 100 || c < 0 || c > 100)
{
MessageBox.Show("Numbers entered incorrectly");
}
else
{
float ort = (a + b + c) / 3;
if (ort < 50)
{
label2.Text = "You failed the class";
}
else
{
label2.Text = "You passed.";
}
}
}