Skip to content

Number app #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
31 changes: 31 additions & 0 deletions Session02/Excample02/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Runtime.CompilerServices;

namespace Excample02
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Do you want to enter your name? (y/n)");
var key = Console.ReadKey();

if (key.KeyChar == 'n')
return;

else if (key.KeyChar == 'y')
{
Console.WriteLine("\nEnter your name: ");
var name = Console.ReadLine();

Console.WriteLine($"Hello, {name}");
}
else
{
Console.WriteLine("\nI don't understand?");
}
Console.WriteLine("Press any key to exit program...");
Console.ReadKey(true);
}
}
}
8 changes: 8 additions & 0 deletions Session02/Excample02/Session02exercise02.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

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

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30413.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Exercise01", "Session02Exercise01\Session02Exercise01.csproj", "{5781BFBB-1E01-47F7-A1DE-5BD53D78E140}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02exercise02", "Excample02\Session02exercise02.csproj", "{6B5DA0D0-23A1-47A2-B34F-A0A125A584FD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Excersise03", "Session02Excersise03\Session02Excersise03.csproj", "{4309C8FA-CF78-44EB-9535-36703D508250}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Excersise04", "Session02Excersise04\Session02Excersise04.csproj", "{85B305B6-E306-4951-ADE5-01656F70DA96}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5781BFBB-1E01-47F7-A1DE-5BD53D78E140}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5781BFBB-1E01-47F7-A1DE-5BD53D78E140}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5781BFBB-1E01-47F7-A1DE-5BD53D78E140}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5781BFBB-1E01-47F7-A1DE-5BD53D78E140}.Release|Any CPU.Build.0 = Release|Any CPU
{6B5DA0D0-23A1-47A2-B34F-A0A125A584FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B5DA0D0-23A1-47A2-B34F-A0A125A584FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B5DA0D0-23A1-47A2-B34F-A0A125A584FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B5DA0D0-23A1-47A2-B34F-A0A125A584FD}.Release|Any CPU.Build.0 = Release|Any CPU
{4309C8FA-CF78-44EB-9535-36703D508250}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4309C8FA-CF78-44EB-9535-36703D508250}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4309C8FA-CF78-44EB-9535-36703D508250}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4309C8FA-CF78-44EB-9535-36703D508250}.Release|Any CPU.Build.0 = Release|Any CPU
{85B305B6-E306-4951-ADE5-01656F70DA96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{85B305B6-E306-4951-ADE5-01656F70DA96}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85B305B6-E306-4951-ADE5-01656F70DA96}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85B305B6-E306-4951-ADE5-01656F70DA96}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B8AA34BE-8E82-4BCB-85BD-2689F1C50616}
EndGlobalSection
EndGlobal
81 changes: 81 additions & 0 deletions Session02/Session02Excersise03/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Net.WebSockets;

namespace Session02Excersise03
{
class Program
{
static void Main(string[] args)
{
//Binary operation
var additionResult = 1 + 2;
Console.WriteLine($"Addition result {additionResult}");

var incrementResult = ++additionResult;
Console.WriteLine($"Increment result {incrementResult}");

var trueValue = true;

var falseValue = false;

// Bitwise operationer
var andResult = 0b0010 & 0b0100; //0b0110;
var orResult = 0b0001 | 0b0001; //0b0001;
var xorResult = 0b0001 ^ 0b0001; //0b0000;

Console.WriteLine($"and result {andResult}");
Console.WriteLine($"or result {orResult}");
Console.WriteLine($"xor result {xorResult}");

var modulResult = 3 % 2;
Console.WriteLine($"modul result {modulResult}");

var highInteger = 1000;
var integerDivisionResult = highInteger / 3;
var doubleDivissionResult = highInteger / 3.0;

Console.WriteLine($"integer division result {integerDivisionResult}");
Console.WriteLine($"double division result {doubleDivissionResult}");

//implicit värdekonvertering till double
var forcedIntDivisionResult = (int)(highInteger / 3.0);
Console.WriteLine($"forced int division result {forcedIntDivisionResult}");

var conversionResult = Convert.ToInt32(doubleDivissionResult);

Console.WriteLine($"Conversion result {conversionResult}");

var midpointDivisionResult = 10.0 / 3.0;

Console.WriteLine($"Midpoint division result {midpointDivisionResult}");
Console.WriteLine($"castToInt" + ((int)midpointDivisionResult).ToString());
Console.WriteLine($"ceiling " + Math.Ceiling(midpointDivisionResult));
Console.WriteLine($"floor " + Math.Floor(midpointDivisionResult));
Console.WriteLine($"ceiling " + Math.Round(midpointDivisionResult));

//T
additionResult += 2; //Samma som (additionalResult = additionalResult + 2)
additionResult -= 2;
additionResult *= 2;
additionResult /= 2;

//Boelska jämförelseoperatorer
var greaterThanResult = 5 > 3;
var lessThanResult = 5 < 3;
var greaterOrEqual = 5 >= 5;
var lessOrEqual = 3 <= 5;

Console.WriteLine($"greaterThanResult {greaterThanResult}");
Console.WriteLine($"lessThanResult {lessThanResult}");
Console.WriteLine($"greater or Equal {greaterOrEqual}");
Console.WriteLine($"less or equal {lessOrEqual}");

var andOperationsResult = true && false;
var orOperationResult = false || true;

Console.WriteLine($"And operations Result {andOperationsResult}");
Console.WriteLine($"Or operations Result {orOperationResult}");
Console.ReadKey(true);
}
}
}
8 changes: 8 additions & 0 deletions Session02/Session02Excersise03/Session02Excersise03.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
40 changes: 40 additions & 0 deletions Session02/Session02Excersise04/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;

namespace Session02Excersise04
{
class Program
{
static void Main(string[] args)
{
//Console.WriteLine("Ange ålder: ");

//var input = Console.ReadLine();
//var integer = Convert.ToInt32(input);

//if (integer >= 18)
//{
// Console.WriteLine("Du får köpa tobaksprodukter.");
//}
//else
//{
// Console.WriteLine("Du får inte köpa tobak! ");
//}

//if (integer >= 40)
//{
// Console.WriteLine("Men du är för gammal för att röka!");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tur att jag slutade.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha! Ja jag med. Snusar gör jag tyvärr.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gjorde jag med fram till för 3 år sedan. Dyrt och jobbigt att sluta.

//}

Console.WriteLine("Ange en badtemperatur i grader C: ");

var input = Console.ReadLine();
var integer = Convert.ToInt32(input);

string waterLabel = integer >= 27 ? "Det går bra att bada" : "Det går inte att bada";
Console.WriteLine($"{waterLabel} i havet!");

Console.WriteLine("Tryck på valfri tangent för att avsluta...");
Console.ReadKey(true);
}
}
}
8 changes: 8 additions & 0 deletions Session02/Session02Excersise04/Session02Excersise04.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
18 changes: 18 additions & 0 deletions Session02/Session02Exercise01/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace Session02Exercise01
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello world!");
var integer = 0;
Console.WriteLine("integer is" + integer.ToString());

string stringValue = "My string is cool!";

Console.WriteLine($"The string value of stringValie is {stringValue}");
}
}
}
8 changes: 8 additions & 0 deletions Session02/Session02Exercise01/Session02Exercise01.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

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

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30413.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session03Exersise01", "Session03Exersise01\Session03Exersise01.csproj", "{9C90BA88-D314-4C64-8D2C-BDE6CA882C1E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9C90BA88-D314-4C64-8D2C-BDE6CA882C1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9C90BA88-D314-4C64-8D2C-BDE6CA882C1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C90BA88-D314-4C64-8D2C-BDE6CA882C1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C90BA88-D314-4C64-8D2C-BDE6CA882C1E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DAB41CAE-214D-40AB-BD39-8D5A82665136}
EndGlobalSection
EndGlobal
92 changes: 92 additions & 0 deletions Session03/Session03Exersise01/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System;
using System.Globalization;
using System.Linq;

namespace Session03Exersise01
{
class Program
{
static void Main(string[] args)
{
double doubleMid = 0;
double dblSum = 0;
int intParsedOk = 0;

Console.WriteLine("Ange ett antal siffror, separerat med kommatecken");
var input = Console.ReadLine();
var inputArray = input.Split(",", StringSplitOptions.RemoveEmptyEntries);
double?[] numberArray = new double?[inputArray.Length];

for (int i = 0; i < inputArray.Length; i++)
{
bool parsed;

try
{
numberArray[i] = Convert.ToDouble(inputArray[i]);
parsed = true;
intParsedOk++;
}

catch (Exception)
{
numberArray[i] = 0;
parsed = false;
}

if (parsed == false)
{
continue;
}

dblSum += numberArray[i].Value;
}
doubleMid = dblSum / intParsedOk;


Console.WriteLine($"Min value is: {numberArray.Min()} Maxvalue is: {numberArray.Max()} Total value is: {dblSum} Midvalue is: {doubleMid :f2}");

Console.WriteLine("\nPress any key to quit program...");
Console.ReadKey(true);

//for (int i = 0; i < inputArray.Length; i++)
//{
// NumberStyles numberStyle = NumberStyles.Integer | NumberStyles.Float; //Bestämmer vilken typ man vill parsa till!
// IFormatProvider formatProvider = new CultureInfo("sv-SE"); //CultureInfo.InvariantCulture;
// IFormatProvider currentNulture = CultureInfo.CurrentCulture;*/

// bool parsed = double.TryParse(inputArray[i], out double parsedValue);



//if (parsed == true)
//{
// numberArray[i] = parsedValue;
//}
//else
//{
// numberArray[i] = null;
//}
}

//static double GetDoubleValue(string input)
//{
// try
// {
// //numberArray[i] = Convert.ToDouble(inputArray[i]);
// var result = int.Parse(input);
// return result;
// }
// catch (FormatException ex)
// {
// return double.MinValue;

// throw ex;
// }
// catch (Exception ex)
// {
// return 0;
// }
//}
}
}
8 changes: 8 additions & 0 deletions Session03/Session03Exersise01/Session03Exersise01.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>