"codealong" innkapsling

This commit is contained in:
Geir Okkenhaug Jerstad 2024-12-02 13:07:40 +01:00
parent 250764b7ef
commit 4879b3bd6f
4 changed files with 52 additions and 0 deletions

View file

@ -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

View file

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View file

@ -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}"
);
}

View file

@ -0,0 +1,6 @@
namespace Innkapsling;
public class Stats
{
}