From 4879b3bd6fc9c25a11b670e1cca2ec9e9f341982 Mon Sep 17 00:00:00 2001 From: Geir Okkenhaug Jerstad Date: Mon, 2 Dec 2024 13:07:40 +0100 Subject: [PATCH] "codealong" innkapsling --- Emne 3/Innkapsling/Innkapsling.sln | 16 +++++++++++++++ .../Innkapsling/Innkapsling.csproj | 10 ++++++++++ Emne 3/Innkapsling/Innkapsling/Program.cs | 20 +++++++++++++++++++ Emne 3/Innkapsling/Innkapsling/Stats.cs | 6 ++++++ 4 files changed, 52 insertions(+) create mode 100644 Emne 3/Innkapsling/Innkapsling.sln create mode 100644 Emne 3/Innkapsling/Innkapsling/Innkapsling.csproj create mode 100644 Emne 3/Innkapsling/Innkapsling/Program.cs create mode 100644 Emne 3/Innkapsling/Innkapsling/Stats.cs diff --git a/Emne 3/Innkapsling/Innkapsling.sln b/Emne 3/Innkapsling/Innkapsling.sln new file mode 100644 index 0000000..c748bb1 --- /dev/null +++ b/Emne 3/Innkapsling/Innkapsling.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Innkapsling", "Innkapsling\Innkapsling.csproj", "{659C61BB-980F-4911-9652-E1C407E7DCBC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {659C61BB-980F-4911-9652-E1C407E7DCBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {659C61BB-980F-4911-9652-E1C407E7DCBC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {659C61BB-980F-4911-9652-E1C407E7DCBC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {659C61BB-980F-4911-9652-E1C407E7DCBC}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Emne 3/Innkapsling/Innkapsling/Innkapsling.csproj b/Emne 3/Innkapsling/Innkapsling/Innkapsling.csproj new file mode 100644 index 0000000..2f4fc77 --- /dev/null +++ b/Emne 3/Innkapsling/Innkapsling/Innkapsling.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/Emne 3/Innkapsling/Innkapsling/Program.cs b/Emne 3/Innkapsling/Innkapsling/Program.cs new file mode 100644 index 0000000..4403cd1 --- /dev/null +++ b/Emne 3/Innkapsling/Innkapsling/Program.cs @@ -0,0 +1,20 @@ + +var numbers = new int[100]; +var numberCount = 0; +while (true) +{ + Console.WriteLine("Skriv et tall (eller blankt for å avslutte: "); + var numberStr = Console.ReadLine(); + if (string.IsNullOrWhiteSpace(numberStr)) break; + + var number = Convert.ToInt32(numberStr); + numbers[numberCount] = number; + numberCount++; + var sum = numbers.Sum(); + Console.Clear(); + Console.WriteLine( + $"Antall tall: {numberCount} " + + $"Sum: {sum} " + + $"Snitt: {(float)sum / numberCount}" + ); +} \ No newline at end of file diff --git a/Emne 3/Innkapsling/Innkapsling/Stats.cs b/Emne 3/Innkapsling/Innkapsling/Stats.cs new file mode 100644 index 0000000..8e4493c --- /dev/null +++ b/Emne 3/Innkapsling/Innkapsling/Stats.cs @@ -0,0 +1,6 @@ +namespace Innkapsling; + +public class Stats +{ + +} \ No newline at end of file