diff --git a/Emne 3/ConsoleApp10HvaGjørKoden/ConsoleApp10HvaGjørKoden.csproj b/Emne 3/ConsoleApp10HvaGjørKoden/ConsoleApp10HvaGjørKoden.csproj new file mode 100644 index 0000000..2f4fc77 --- /dev/null +++ b/Emne 3/ConsoleApp10HvaGjørKoden/ConsoleApp10HvaGjørKoden.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/Emne 3/ConsoleApp10HvaGjørKoden/ConsoleApp10HvaGjørKoden.sln b/Emne 3/ConsoleApp10HvaGjørKoden/ConsoleApp10HvaGjørKoden.sln new file mode 100644 index 0000000..fc5a5bc --- /dev/null +++ b/Emne 3/ConsoleApp10HvaGjørKoden/ConsoleApp10HvaGjørKoden.sln @@ -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 diff --git a/Emne 3/ConsoleApp10HvaGjørKoden/Program.cs b/Emne 3/ConsoleApp10HvaGjørKoden/Program.cs new file mode 100644 index 0000000..1f94dea --- /dev/null +++ b/Emne 3/ConsoleApp10HvaGjørKoden/Program.cs @@ -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)); + } + } +} \ No newline at end of file