Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file added .vs/Calculator/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .vs/Calculator/v17/.futdcache.v2
Binary file not shown.
Binary file added .vs/Calculator/v17/.suo
Binary file not shown.
12 changes: 12 additions & 0 deletions .vs/Calculator/v17/DocumentLayout.backup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Version": 1,
"WorkspaceRootPath": "C:\\Users\\timso\\source\\repos\\Calculator\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": []
}
]
}
12 changes: 12 additions & 0 deletions .vs/Calculator/v17/DocumentLayout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Version": 1,
"WorkspaceRootPath": "C:\\Users\\timso\\source\\repos\\Calculator\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": []
}
]
}
Binary file added .vs/ProjectEvaluation/calculator.metadata.v9.bin
Binary file not shown.
Binary file added .vs/ProjectEvaluation/calculator.projects.v9.bin
Binary file not shown.
Binary file added .vs/ProjectEvaluation/calculator.strings.v9.bin
Binary file not shown.
14 changes: 14 additions & 0 deletions Calculator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\CalculatorLibrary\CalculatorLibrary.csproj" />
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions Calculator.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36603.0 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Calculator", "Calculator.csproj", "{68E3F897-DD0C-4B67-A289-933BA1552A19}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CalculatorLibrary", "..\CalculatorLibrary\CalculatorLibrary.csproj", "{87AC7B51-A530-429F-8322-53BF20DC73FA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{68E3F897-DD0C-4B67-A289-933BA1552A19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68E3F897-DD0C-4B67-A289-933BA1552A19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68E3F897-DD0C-4B67-A289-933BA1552A19}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68E3F897-DD0C-4B67-A289-933BA1552A19}.Release|Any CPU.Build.0 = Release|Any CPU
{87AC7B51-A530-429F-8322-53BF20DC73FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{87AC7B51-A530-429F-8322-53BF20DC73FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87AC7B51-A530-429F-8322-53BF20DC73FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87AC7B51-A530-429F-8322-53BF20DC73FA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {876BAC24-451C-4923-9DB7-98E3392A4562}
EndGlobalSection
EndGlobal
87 changes: 87 additions & 0 deletions CalculatorProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using CalculatorLibrary;
using System.Text.RegularExpressions;

class CalculatorProgram
{
static void Main(string[] args)
{
bool endApp = false;
int count = 0;
Console.WriteLine("Console Calculator in C#\r");
Console.WriteLine("------------------------\n");

Calculator calculator = new Calculator();
while (!endApp)
{
string? numInput1 = "";
string? numInput2 = "";
double result = 0;

Console.WriteLine("Enter first number:");
numInput1 = Console.ReadLine();

double cleanNum1 = 0;
while (!double.TryParse(numInput1, out cleanNum1))
{
Console.WriteLine("This is not valid input. Please enter a valid number:");
numInput1 = Console.ReadLine();
}

Console.WriteLine("Enter second number:");
numInput2 = Console.ReadLine();

double cleanNum2 = 0;
while (!double.TryParse(numInput2, out cleanNum2))
{
Console.WriteLine("This is not valid input. Please enter a valid number:");
numInput2 = Console.ReadLine();
}

Console.WriteLine("Choose an operator from the following list:");
Console.WriteLine("\ta - Add");
Console.WriteLine("\ts - Subtract");
Console.WriteLine("\tm - Multiply");
Console.WriteLine("\td - Divide");
Console.Write("Your option? ");

string? op = Console.ReadLine();

if (op == null || !Regex.IsMatch(op, "[a|s|m|d]"))
{
Console.WriteLine("Error: Unrecognised input.");
}
else
{
try
{
result = calculator.DoOperation(cleanNum1, cleanNum2, op);
if (double.IsNaN(result))
{
Console.WriteLine("This operation will result in mathematical error.\n");
}
else
{
Console.WriteLine("Your result: {0:0.##}\n", result);
}
}
catch (Exception e)
{
Console.WriteLine("Oh no! An exception occurred trying to do the math.\n - Details: " + e.Message);
}
}
count++;
Console.WriteLine("------------------------\n");
Console.WriteLine($"You've used the Calculator {count} times in a row.");
Console.Write("Press 'n' and Enter to close the app, or press any other key and Enter to continue: ");
if (Console.ReadLine() == "n")
{
endApp = true;
}


Console.WriteLine("\n");
}
calculator.Finish();
return;
}
}
57 changes: 57 additions & 0 deletions bin/Debug/net8.0/Calculator.deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v8.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v8.0": {
"Calculator/1.0.0": {
"dependencies": {
"CalculatorLibrary": "1.0.0"
},
"runtime": {
"Calculator.dll": {}
}
},
"Newtonsoft.Json/13.0.4": {
"runtime": {
"lib/net6.0/Newtonsoft.Json.dll": {
"assemblyVersion": "13.0.0.0",
"fileVersion": "13.0.4.30916"
}
}
},
"CalculatorLibrary/1.0.0": {
"dependencies": {
"Newtonsoft.Json": "13.0.4"
},
"runtime": {
"CalculatorLibrary.dll": {
"assemblyVersion": "1.0.0.0",
"fileVersion": "1.0.0.0"
}
}
}
}
},
"libraries": {
"Calculator/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Newtonsoft.Json/13.0.4": {
"type": "package",
"serviceable": true,
"sha512": "sha512-pdgNNMai3zv51W5aq268sujXUyx7SNdE2bj1wZcWjAQrKMFZV260lbqYop1d2GM67JI1huLRwxo9ZqnfF/lC6A==",
"path": "newtonsoft.json/13.0.4",
"hashPath": "newtonsoft.json.13.0.4.nupkg.sha512"
},
"CalculatorLibrary/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
Binary file added bin/Debug/net8.0/Calculator.dll
Binary file not shown.
Binary file added bin/Debug/net8.0/Calculator.exe
Binary file not shown.
Binary file added bin/Debug/net8.0/Calculator.pdb
Binary file not shown.
12 changes: 12 additions & 0 deletions bin/Debug/net8.0/Calculator.runtimeconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"runtimeOptions": {
"tfm": "net8.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "8.0.0"
},
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}
Binary file added bin/Debug/net8.0/CalculatorLibrary.dll
Binary file not shown.
Binary file added bin/Debug/net8.0/CalculatorLibrary.pdb
Binary file not shown.
Binary file added bin/Debug/net8.0/Newtonsoft.Json.dll
Binary file not shown.
4 changes: 4 additions & 0 deletions bin/Debug/net8.0/calculator.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Starting Calculator Log
Started 2026-01-13 9:45:00 AM
1 + 2 = 3
3 * 3 = 9
2 changes: 2 additions & 0 deletions bin/Debug/net8.0/calculatorlog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"Operations": [
148 changes: 148 additions & 0 deletions obj/Calculator.csproj.nuget.dgspec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"format": 1,
"restore": {
"C:\\Users\\timso\\source\\repos\\Calculator\\Calculator.csproj": {}
},
"projects": {
"C:\\Users\\timso\\source\\repos\\CalculatorLibrary\\CalculatorLibrary.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\timso\\source\\repos\\CalculatorLibrary\\CalculatorLibrary.csproj",
"projectName": "CalculatorLibrary",
"projectPath": "C:\\Users\\timso\\source\\repos\\CalculatorLibrary\\CalculatorLibrary.csproj",
"packagesPath": "C:\\Users\\timso\\.nuget\\packages\\",
"outputPath": "C:\\Users\\timso\\source\\repos\\CalculatorLibrary\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\timso\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
},
"SdkAnalysisLevel": "9.0.300"
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"dependencies": {
"Newtonsoft.Json": {
"target": "Package",
"version": "[13.0.4, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.306/PortableRuntimeIdentifierGraph.json"
}
}
},
"C:\\Users\\timso\\source\\repos\\Calculator\\Calculator.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\timso\\source\\repos\\Calculator\\Calculator.csproj",
"projectName": "Calculator",
"projectPath": "C:\\Users\\timso\\source\\repos\\Calculator\\Calculator.csproj",
"packagesPath": "C:\\Users\\timso\\.nuget\\packages\\",
"outputPath": "C:\\Users\\timso\\source\\repos\\Calculator\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\timso\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {
"C:\\Users\\timso\\source\\repos\\CalculatorLibrary\\CalculatorLibrary.csproj": {
"projectPath": "C:\\Users\\timso\\source\\repos\\CalculatorLibrary\\CalculatorLibrary.csproj"
}
}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
},
"SdkAnalysisLevel": "9.0.300"
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.306/PortableRuntimeIdentifierGraph.json"
}
}
}
}
}
Loading