Compare commits

..

No commits in common. "32933758fe96908f2be91aa430270c768826012c" and "4879b3bd6fc9c25a11b670e1cca2ec9e9f341982" have entirely different histories.

2 changed files with 10 additions and 20 deletions

View file

@ -1,7 +1,6 @@
 
using Innkapsling; var numbers = new int[100];
var numberCount = 0;
var stats = new Stats();
while (true) while (true)
{ {
Console.WriteLine("Skriv et tall (eller blankt for å avslutte: "); Console.WriteLine("Skriv et tall (eller blankt for å avslutte: ");
@ -9,12 +8,13 @@ while (true)
if (string.IsNullOrWhiteSpace(numberStr)) break; if (string.IsNullOrWhiteSpace(numberStr)) break;
var number = Convert.ToInt32(numberStr); var number = Convert.ToInt32(numberStr);
stats.AddNumber(number); numbers[numberCount] = number;
numberCount++;
var sum = numbers.Sum();
Console.Clear(); Console.Clear();
Console.WriteLine( Console.WriteLine(
$"Antall tall: {stats.NumberCount} " + $"Antall tall: {numberCount} " +
$"Sum: {stats.Sum} " + $"Sum: {sum} " +
$"Snitt: {stats.Mean}" $"Snitt: {(float)sum / numberCount}"
); );
} }

View file

@ -1,16 +1,6 @@
namespace Innkapsling; 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++;
}
} }