Hva gjør koden
This commit is contained in:
parent
2c3f93d0c4
commit
3cb41d15d7
|
@ -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>
|
16
Emne 3/ConsoleApp10HvaGjørKoden/ConsoleApp10HvaGjørKoden.sln
Normal file
16
Emne 3/ConsoleApp10HvaGjørKoden/ConsoleApp10HvaGjørKoden.sln
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp10HvaGjørKoden", "ConsoleApp10HvaGjørKoden.csproj", "{9146E1AB-594E-4929-A80F-0EE9AAA85311}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{9146E1AB-594E-4929-A80F-0EE9AAA85311}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{9146E1AB-594E-4929-A80F-0EE9AAA85311}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{9146E1AB-594E-4929-A80F-0EE9AAA85311}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{9146E1AB-594E-4929-A80F-0EE9AAA85311}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
26
Emne 3/ConsoleApp10HvaGjørKoden/Program.cs
Normal file
26
Emne 3/ConsoleApp10HvaGjørKoden/Program.cs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
var range = 250;
|
||||||
|
var counts = new int[range];
|
||||||
|
int totalLetters = 0;
|
||||||
|
string text = "something";
|
||||||
|
while (!string.IsNullOrWhiteSpace(text))
|
||||||
|
{
|
||||||
|
text = Console.ReadLine();
|
||||||
|
Console.Clear();
|
||||||
|
foreach (var character in text.ToLower() ?? string.Empty)
|
||||||
|
{
|
||||||
|
totalLetters++;
|
||||||
|
counts[(int)character]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < range; i++)
|
||||||
|
{
|
||||||
|
if (counts[i] > 0)
|
||||||
|
{
|
||||||
|
// Måtte jukse litt for jeg hadde: var percentage = counts[i] / totalLetters * 100; som var feil matte
|
||||||
|
var character = (char)i;
|
||||||
|
var percentage = 100 * counts[i] / totalLetters ;
|
||||||
|
// string output = counts[i] + " - " + character + " - " + percentage + "%";
|
||||||
|
Console.WriteLine(String.Format("{0,0} - {1,1} - {2,2}%", counts[i], character, percentage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue