I am taking a programming class in C# and here is my first assignment, and already I am in need of help. I think I can handle the problem I just need help getting started.
Create an Average class with a public data member to collect the sum of the integer entries and a public data member to hold the double average of the sum of the 10 integers.
- Public class method to get each integer number input.
- Public class method to calculate the average of the numbers input.
- Public class method to output the average of the numbers input.
- Main( ) function that instantiates one Average object, and includes a for loop to take 10 inputs and calls to the calculation and output method.
The next chapter covers looping, however, you should be able to build a for-loop to accomplish the 10 inputs.
namespace Assignment1_White
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int num1;
int num2;
int num3;
int num4;
int num5;
int num6;
int num7;
int num8;
int num9;
int num10;
int answer;
num1 = int.Parse(num100.Text);
num2 = int.Parse(num200.Text);
num3 = int.Parse(num300.Text);
num4 = int.Parse(num400.Text);
num5 = int.Parse(num500.Text);
num6 = int.Parse(num600.Text);
num7 = int.Parse(num700.Text);
num8 = int.Parse(num800.Text);
num9 = int.Parse(num900.Text);
num10 = int.Parse(num1000.Text);
answer = (num1 + num2 + num3 + num4 + num5 + num6 + num7 + num8 + num9 +num10)/10;
MessageBox.Show(answer.ToString());
}
}
I got this far but now I am stuck on error checking. Currently it will divide by 10 everytime. I need a way to add an if statement.