Compare commits
No commits in common. "32933758fe96908f2be91aa430270c768826012c" and "4879b3bd6fc9c25a11b670e1cca2ec9e9f341982" have entirely different histories.
32933758fe
...
4879b3bd6f
|
@ -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;
|
||||||
Console.Clear();
|
numberCount++;
|
||||||
|
var sum = numbers.Sum();
|
||||||
|
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}"
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
|
@ -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++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue