add isbn fun

main
Fionn 3 years ago
parent 1ef47c6ff5
commit 84450a009a

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

@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>

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

@ -33,6 +33,7 @@ while (true)
if (!int.TryParse(sign, out val)) if (!int.TryParse(sign, out val))
{ {
skip = true;
break; break;
} }

Loading…
Cancel
Save