Skip to content

Numbers #6

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 8 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
43 changes: 43 additions & 0 deletions Session02/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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Session02Exercise01", "Session02Exercise01\Session02Exercise01.csproj", "{F7CC7696-115A-4241-B143-120AB0A3F60B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Exercise02", "Session02Exercise02\Session02Exercise02.csproj", "{F87226E1-856F-4A22-B01A-15C9C2C1B179}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solution02Example04", "Solution02Example04\Solution02Example04.csproj", "{C1FA6E96-F933-45BC-BC22-6BE7ABE72636}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solution02Example05", "Solution02Example05\Solution02Example05.csproj", "{6B150AC3-1C40-4CBA-94DB-F0D6EF27D410}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F7CC7696-115A-4241-B143-120AB0A3F60B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7CC7696-115A-4241-B143-120AB0A3F60B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7CC7696-115A-4241-B143-120AB0A3F60B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7CC7696-115A-4241-B143-120AB0A3F60B}.Release|Any CPU.Build.0 = Release|Any CPU
{F87226E1-856F-4A22-B01A-15C9C2C1B179}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F87226E1-856F-4A22-B01A-15C9C2C1B179}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F87226E1-856F-4A22-B01A-15C9C2C1B179}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F87226E1-856F-4A22-B01A-15C9C2C1B179}.Release|Any CPU.Build.0 = Release|Any CPU
{C1FA6E96-F933-45BC-BC22-6BE7ABE72636}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C1FA6E96-F933-45BC-BC22-6BE7ABE72636}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1FA6E96-F933-45BC-BC22-6BE7ABE72636}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1FA6E96-F933-45BC-BC22-6BE7ABE72636}.Release|Any CPU.Build.0 = Release|Any CPU
{6B150AC3-1C40-4CBA-94DB-F0D6EF27D410}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B150AC3-1C40-4CBA-94DB-F0D6EF27D410}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B150AC3-1C40-4CBA-94DB-F0D6EF27D410}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B150AC3-1C40-4CBA-94DB-F0D6EF27D410}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EF9E92EC-71B2-472F-B2CA-CE53F3040AF9}
EndGlobalSection
EndGlobal
22 changes: 22 additions & 0 deletions Session02/Session02/Session02Exercise01/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace Session02Exercise01
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");





var integer = 0;
string stringValue = "MyStringValue";

Console.WriteLine("Integer is " + integer.ToString());
Console.WriteLine("The value of stringValue is: " + stringValue);
}
}
}
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>
22 changes: 22 additions & 0 deletions Session02/Session02/Session02Exercise02/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace Session02Exercise02
{
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;

Console.WriteLine("\nEnter your name:");
var name = Console.ReadLine();

Console.WriteLine("Hello, " + name);
Console.ReadKey();
}
}
}
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>
30 changes: 30 additions & 0 deletions Session02/Session02/Solution02Example04/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;

namespace Solution02Example04
{
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 tobaksprodukter");
}

if (integer >= 40)
{
Console.WriteLine("Du är även jättegammal");
}
}
}
}
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>
31 changes: 31 additions & 0 deletions Session02/Session02/Solution02Example05/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;

namespace Solution02Example05
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Ange vattentemperatur i grader C:");

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

string waterLabel = integer >= 27 ? "Går att bada" : "Går inte att bada";

// Är samma sak som
//if (integer > 27)
//{
// waterLabel = "Går att bada";
//}
//else
//{
// waterLabel = "Går inte att bada";
//}



Console.WriteLine(waterLabel + " i havet");
}
}
}
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>
31 changes: 31 additions & 0 deletions Session03/Session03/Session03.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 16
VisualStudioVersion = 16.0.30413.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session03Exercise02", "Session03Exercise02\Session03Exercise02.csproj", "{F8F25BB2-9822-43C4-899B-8102A0552F7D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session03Numbers", "Session03Numbers\Session03Numbers.csproj", "{DD026B75-D062-4537-988E-204B8C353397}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F8F25BB2-9822-43C4-899B-8102A0552F7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F8F25BB2-9822-43C4-899B-8102A0552F7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F8F25BB2-9822-43C4-899B-8102A0552F7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F8F25BB2-9822-43C4-899B-8102A0552F7D}.Release|Any CPU.Build.0 = Release|Any CPU
{DD026B75-D062-4537-988E-204B8C353397}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DD026B75-D062-4537-988E-204B8C353397}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DD026B75-D062-4537-988E-204B8C353397}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DD026B75-D062-4537-988E-204B8C353397}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7E1D272D-D7F3-42FC-A017-131D73DC1330}
EndGlobalSection
EndGlobal
21 changes: 21 additions & 0 deletions Session03/Session03/Session03Exercise02/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace Session03Exercise02
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Ange ett antal siffror, separerat med kommatecken.");
var input = Console.ReadLine();

var inputArray = input.Split(",", StringSplitOptions.RemoveEmptyEntries);

foreach (var number in inputArray)
{
Console.WriteLine("Värdet är " + number);
}

}
}
}
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>
141 changes: 141 additions & 0 deletions Session03/Session03/Session03Numbers/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
using System;
using System.Diagnostics;
using System.Globalization;
using System.Linq;

namespace Session03Numbers
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Ange ett antal siffror, separerat med kommatecken.");
var input = Console.ReadLine();

var inputArray = input.Split(",", StringSplitOptions.RemoveEmptyEntries);

double?[] numbersArray = new double?[inputArray.Length];
double? sum = 0;
double? largest = 0;
double? smallest = 0;
double? average = 0;

for (int i = 0; i < inputArray.Length; i++)
{
//try
//{

// //Debug.Assert(i < inputArray.Length - 1);
//}
//catch (Exception)
//{
// numbersArray[i] = 0;
//}
//finally
//{

//}

NumberStyles numberStyle = NumberStyles.Integer | NumberStyles.Float;

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

if (parsed)
{
numbersArray[i] = parsedValue;
}
else
{
numbersArray[i] = null;
}

//numbersArray[i] = Convert.ToDouble(inputArray[i]);
Console.WriteLine("Värde " + numbersArray[i]);

//sum += numbersArray[i];

}

foreach (double? num in numbersArray)
{
if (num == null)
{
continue;
}
else
{
sum += num;
}
}

largest = numbersArray.Max();
smallest = numbersArray.Min();
average = (float)sum / numbersArray.Length;

// Option 2 for largest & smallest
largest = numbersArray[0];
smallest = numbersArray[0];

foreach(double? num in numbersArray)
{
if (largest < num)
largest = num;

if (smallest > num)
smallest = num;
}


Console.WriteLine($"\nStörsta värdet: {largest}\nLägsta värdet: {smallest}\n" +
$"Antal tal: {numbersArray.Length}\nMedelvärde: {average}");

//int exceptionStatus = getExceptionStatus();
}

//static double GetDoubleValue(string input)
//{
// try
// {
// var result = int.Parse(input);

// return result;
// }
// catch (FormatException ex) when (ex.Message.Contains("Input string"))
// {
// //throw;
// return double.MinValue;

// }
// catch (Exception ex)
// {
// return 0;
// }
//}

//static int getExceptionStatus()
//{
// int exceptionResult;

// try
// {
// exceptionResult = -1;

// throw new Exception("Provocerat fel");

// return exceptionResult;
// }
// catch (Exception ex)
// {
// exceptionResult = ex.HResult;

// return exceptionResult;

// }
// finally
// {
// exceptionResult = int.MaxValue;

// }
// }
}
}
Loading