diff --git a/Checksums/Checksums.sln b/Checksums/Checksums.sln new file mode 100644 index 0000000..35c158b --- /dev/null +++ b/Checksums/Checksums.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32516.85 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ISBN", "ISBN\ISBN.csproj", "{3BFA78C7-4DE1-46CD-912F-59D3DE0B9788}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3BFA78C7-4DE1-46CD-912F-59D3DE0B9788}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3BFA78C7-4DE1-46CD-912F-59D3DE0B9788}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3BFA78C7-4DE1-46CD-912F-59D3DE0B9788}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3BFA78C7-4DE1-46CD-912F-59D3DE0B9788}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2CB662C2-AAB5-42F9-BFF5-DD1A2EDAB997} + EndGlobalSection +EndGlobal diff --git a/Checksums/ISBN/ISBN.csproj b/Checksums/ISBN/ISBN.csproj new file mode 100644 index 0000000..1d2d39a --- /dev/null +++ b/Checksums/ISBN/ISBN.csproj @@ -0,0 +1,8 @@ + + + + Exe + net5.0 + + + diff --git a/Checksums/ISBN/Program.cs b/Checksums/ISBN/Program.cs new file mode 100644 index 0000000..910384a --- /dev/null +++ b/Checksums/ISBN/Program.cs @@ -0,0 +1,83 @@ +using System; +using System.Linq; + +// ISBN-Rechner von Artur, Chris und Fionn + +namespace ISBN +{ + internal class Program + { + static void Main(string[] args) + { + while (true) + { + string input = GetInput(), mode = "NULL"; + + string[] split = input.Select(x => x.ToString()).ToArray(); + + if (split.Count() == 10) mode = "VALIDATE"; + if (split.Count() == 9) mode = "GENERATE"; + + if (mode == "NULL") + { + Console.WriteLine($"\"{input}\" is no valid input. See the rules above for valid input!"); + continue; + } + + bool skip = false; + int temp = 0; + + for(int i = 0; i < 9; i++) + { + string sign = split[i]; + + int parsedInt; + + if(!int.TryParse(sign, out parsedInt)) + { + skip = true; + break; + } + + temp += parsedInt * (i + 1); + } + + if (skip) continue; + + Console.WriteLine(temp); + + temp %= 11; + + string sum = temp == 10 ? "X" : temp.ToString(); + + Console.WriteLine($"Calculated Checksum is {sum}."); + if (mode == "VALIDATE") + { + string inCheck = split[9]; + Console.Write($"{inCheck} was given. "); + Console.WriteLine(inCheck == sum ? "They are the same." : "They are not the same."); + } + Console.WriteLine("\n\n\n"); + } + } + + internal static string GetInput() + { + while (true) + { + Console.Write("Pls input complete ISBN (can be only ISBN-10, with ot without checksum, do not include dashes!):\n-> "); + string input = Console.ReadLine(); + + if (input == null || input == "") continue; + + if (input == "q") + { + Console.WriteLine("Bye bye!"); + Environment.Exit(0); + } + + return input; + } + } + } +} diff --git a/EANValidator/EANValidator/Program.cs b/EANValidator/EANValidator/Program.cs index 12f873d..97da13a 100644 --- a/EANValidator/EANValidator/Program.cs +++ b/EANValidator/EANValidator/Program.cs @@ -33,6 +33,7 @@ while (true) if (!int.TryParse(sign, out val)) { + skip = true; break; }