Create a program named [assignment1_yourlastname.cs] that includes the following
ID: 3531184 • Letter: C
Question
Create a program named[assignment1_yourlastname.cs] that includes the following requirements:
You may look up similar programs on the web or in your books, but be sure you use your code for this project. Commenting blocks of code in the real world is usually sufficient. Document enough to show that you understand what is going on.
An example of possible output would look like this:
Enter an integer value:1
Enter an integer value:2
Enter an integer value:3
Enter an integer value:4
Enter an integer value:5
Enter an integer value:6
Enter an integer value:7
Enter an integer value:8
Enter an integer value:9
Enter an integer value:10
The average is 5.5, the sum of 10 numbers is 55
Press any key to continue . . .
Explanation / Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Average
{
public double average;
public double sum;
public Average() {
average = 0;
sum = 0;
}
public void getInput(){
sum = 0;
int num;
for (int i = 0; i < 10; i++) {
Console.Write("Enter an integer value:");
num = int.Parse(Console.ReadLine());
sum += num;
}
return;
}
public void calcAverage() {
average = sum / 10.0;
}
public void output() {
Console.WriteLine("The average is {0}, the sum of 10 numbers is {1}", average,sum);
}
static void Main(string[] args)
{
Average test = new Average();
test.getInput();
test.calcAverage();
test.output();
Console.Write("Press any key to continue...");
Console.ReadLine(); Console.ReadLine(); //stall compiler from closing for 2 line reads
}//end main
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.