Compare commits
No commits in common. "32933758fe96908f2be91aa430270c768826012c" and "4879b3bd6fc9c25a11b670e1cca2ec9e9f341982" have entirely different histories.
32933758fe
...
4879b3bd6f
|
@ -1,7 +1,6 @@
|
|||
|
||||
using Innkapsling;
|
||||
|
||||
var stats = new Stats();
|
||||
var numbers = new int[100];
|
||||
var numberCount = 0;
|
||||
while (true)
|
||||
{
|
||||
Console.WriteLine("Skriv et tall (eller blankt for å avslutte: ");
|
||||
|
@ -9,12 +8,13 @@ while (true)
|
|||
if (string.IsNullOrWhiteSpace(numberStr)) break;
|
||||
|
||||
var number = Convert.ToInt32(numberStr);
|
||||
stats.AddNumber(number);
|
||||
Console.Clear();
|
||||
numbers[numberCount] = number;
|
||||
numberCount++;
|
||||
var sum = numbers.Sum();
|
||||
Console.Clear();
|
||||
Console.WriteLine(
|
||||
$"Antall tall: {stats.NumberCount} " +
|
||||
$"Sum: {stats.Sum} " +
|
||||
$"Snitt: {stats.Mean}"
|
||||
$"Antall tall: {numberCount} " +
|
||||
$"Sum: {sum} " +
|
||||
$"Snitt: {(float)sum / numberCount}"
|
||||
);
|
||||
|
||||
}
|
|
@ -1,16 +1,6 @@
|
|||
namespace Innkapsling;
|
||||
|
||||
internal class Stats
|
||||
public class Stats
|
||||
{
|
||||
public int NumberCount { get; private set; }
|
||||
public int Sum { get; private set; }
|
||||
|
||||
public float Mean => (float)Sum / NumberCount;
|
||||
|
||||
public void AddNumber(int number)
|
||||
{
|
||||
Sum += number;
|
||||
NumberCount++;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue