Skip to content

Numbers #9

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 10 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions Session02/ConsoleApp1/ConsoleApp1.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}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{0CDB9C9E-2F2C-4E95-9761-DA19DB872C5D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0CDB9C9E-2F2C-4E95-9761-DA19DB872C5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0CDB9C9E-2F2C-4E95-9761-DA19DB872C5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0CDB9C9E-2F2C-4E95-9761-DA19DB872C5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0CDB9C9E-2F2C-4E95-9761-DA19DB872C5D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4025A1B4-422B-40C7-9624-54D828A1EA67}
EndGlobalSection
EndGlobal
8 changes: 8 additions & 0 deletions Session02/ConsoleApp1/ConsoleApp1/ConsoleApp1.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/ConsoleApp1/ConsoleApp1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;

namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var integerValues = new[] { 1, 2, 3 };
var name = nameof(integerValues);
Console.WriteLine("For-loop");
for (var i = 0; i < integerValues.Length; i++)
{
var value = integerValues[i];

Console.WriteLine($"Index {i} i arrayen {name} har värdet: {value}");
}
Console.WriteLine();
Console.WriteLine("Do-while-loop");
var doWhileIndex = 0;
do
{
var value = integerValues[doWhileIndex];
Console.WriteLine($"Index {doWhileIndex} i arrayen {name} har värdet: {value}");
doWhileIndex++;
}
while (doWhileIndex < integerValues.Length);

var whileIndex = 0;
Console.WriteLine();
Console.WriteLine("While-loop");
while(whileIndex < integerValues.Length)
{
var value = integerValues[whileIndex];
Console.WriteLine($"Index {whileIndex} i arrayen {name} har värdet: {value}");
whileIndex++;
}
Comment on lines +9 to +37
Copy link
Owner

Choose a reason for hiding this comment

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

Denna kod skulle må bra av lite tomma rader. Prova att lägga in en före och efter varje Console.Write som ligger utanför kodblock.

var integerValues = new[] { 1, 2, 3 };
var name = nameof(integerValues);

Console.WriteLine("For-loop");

for (var i = 0; i < integerValues.Length; i++)

}
}
}
8 changes: 8 additions & 0 deletions Session02/Session02/ConsoleApp1/ConsoleApp1.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>
71 changes: 71 additions & 0 deletions Session02/Session02/ConsoleApp1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;

namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var additionResult = 1 + 2;
Console.WriteLine("Additionresult: " + additionResult);
var incrementResult1 = additionResult++;
var incrementResult2 = ++additionResult;
Console.WriteLine("incrementresult: " + incrementResult1);
Console.WriteLine("incrementresult: " + incrementResult2);

var trueValue = true;
var falseValue = false;

// Inte boolsk jämförelse
var andResult = 0b0010 & 0b0100; // 0b0110
var orResult = trueValue | falseValue;
var xorResult = trueValue ^ falseValue;

Console.WriteLine("andResult: " + andResult);
Console.WriteLine("orResult: " + orResult);
Console.WriteLine("xorValue: " + xorResult);

var moduleResult = 3 % 2;

Console.WriteLine("ModuleResult: " + moduleResult);

var highInteger = 1000;
var divisionResult = highInteger / 3;
// Implicit värdekonvertering till double
var doubleDivisionResult = highInteger / 3.0;

var forcedIntDivisionResult = (int)(highInteger / 3.0);

Console.WriteLine("DivisionResult: " + divisionResult);
Console.WriteLine("DoubleDivisionResult: " + doubleDivisionResult);
Console.WriteLine("forcedIntDivisionResult: " + forcedIntDivisionResult);

var conversionResult = Convert.ToInt32(doubleDivisionResult);
Console.WriteLine("conversionResult: " + conversionResult);

var midpointDivisionResult = 1.0 / 3.0;

Console.WriteLine("midpointDivisionResult: " + midpointDivisionResult);
Console.WriteLine("castToInt: " + ((int)midpointDivisionResult));
Console.WriteLine("Ceiling: " + Math.Ceiling(midpointDivisionResult));
Console.WriteLine("Floor: " + Math.Floor(midpointDivisionResult));
Console.WriteLine("Round: " + Math.Round(midpointDivisionResult, 3));

//Det går även att använda sammanslagna operatorer
// -=
// +=
// *=
// /=

// Finns även <=, >=, ==,
var greaterResult = 5 > 3;
var lessThanResult = 5 < 3;

Console.WriteLine("greaterThanREsult: " + greaterResult);
Console.WriteLine("lessThanResult: " + lessThanResult);



}
}
}
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}") = "Session02Excercise01", "Session02Excercise01\Session02Excercise01.csproj", "{19876383-95F1-4AF9-AED1-87B1940C5CA4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Exercise02", "Session02Exercise02\Session02Exercise02.csproj", "{B6BA7FFB-6B0D-4079-B268-2E00DA25480D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{FABF555D-DB61-4EE6-AD9F-A6FC603412FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Example04", "Session02Example04\Session02Example04.csproj", "{18E7D114-46CA-494E-819B-031C8EC8420D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{19876383-95F1-4AF9-AED1-87B1940C5CA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19876383-95F1-4AF9-AED1-87B1940C5CA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19876383-95F1-4AF9-AED1-87B1940C5CA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19876383-95F1-4AF9-AED1-87B1940C5CA4}.Release|Any CPU.Build.0 = Release|Any CPU
{B6BA7FFB-6B0D-4079-B268-2E00DA25480D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6BA7FFB-6B0D-4079-B268-2E00DA25480D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6BA7FFB-6B0D-4079-B268-2E00DA25480D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6BA7FFB-6B0D-4079-B268-2E00DA25480D}.Release|Any CPU.Build.0 = Release|Any CPU
{FABF555D-DB61-4EE6-AD9F-A6FC603412FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FABF555D-DB61-4EE6-AD9F-A6FC603412FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FABF555D-DB61-4EE6-AD9F-A6FC603412FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FABF555D-DB61-4EE6-AD9F-A6FC603412FB}.Release|Any CPU.Build.0 = Release|Any CPU
{18E7D114-46CA-494E-819B-031C8EC8420D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{18E7D114-46CA-494E-819B-031C8EC8420D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18E7D114-46CA-494E-819B-031C8EC8420D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18E7D114-46CA-494E-819B-031C8EC8420D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {29AF081A-69D3-4EEB-A68C-563945E90467}
EndGlobalSection
EndGlobal
51 changes: 51 additions & 0 deletions Session02/Session02/Session02Example04/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;

namespace Session02Example04
{
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 jättegammal");
}

Console.WriteLine("Ange vattentemperatur i grader C: ");
var input1 = Console.ReadLine();
var integer1 = Convert.ToInt32(input1);
Comment on lines +28 to +29
Copy link
Owner

Choose a reason for hiding this comment

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

Här skulle man helt enkelt kunna återanvända input och integer utan att skapa nya variabler.

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


string waterLabel = integer1 >= 27 ? "Går att bada" : "Går inte att bada";
//if (integer1 >= 27)
//{
//Console.WriteLine("Går att bada");
//}
//else
//{
// Console.WriteLine("Det går inte att bada");
//}

switch (integer1)
{
case 1: waterLabel = "Går inte att bada alls"; break;
case -3: waterLabel = "Det är 3 minusgrader"; break;
}
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>
18 changes: 18 additions & 0 deletions Session02/Session02/Session02Excercise01/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace Session02Excercise01
{
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("Enter 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>
23 changes: 23 additions & 0 deletions Session02/Session02ex02/Session02Exercise02/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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("Enter 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>
25 changes: 25 additions & 0 deletions Session02/Session02ex02/Session02ex02.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}") = "Session02Exercise02", "Session02Exercise02\Session02Exercise02.csproj", "{B1019ED2-4FE5-428A-BBDE-C759C7A53C90}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B1019ED2-4FE5-428A-BBDE-C759C7A53C90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1019ED2-4FE5-428A-BBDE-C759C7A53C90}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1019ED2-4FE5-428A-BBDE-C759C7A53C90}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1019ED2-4FE5-428A-BBDE-C759C7A53C90}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {49EFCB3E-6855-4062-BC6E-F9B69B92A772}
EndGlobalSection
EndGlobal
25 changes: 25 additions & 0 deletions Session02/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}") = "Session03Exercise02", "Session03Exercise02\Session03Exercise02.csproj", "{8BDD4CF9-8135-44E8-8604-0650A7FD6D28}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8BDD4CF9-8135-44E8-8604-0650A7FD6D28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8BDD4CF9-8135-44E8-8604-0650A7FD6D28}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8BDD4CF9-8135-44E8-8604-0650A7FD6D28}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8BDD4CF9-8135-44E8-8604-0650A7FD6D28}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CBE1BF82-DE25-495C-B0C8-733790FC6FDE}
EndGlobalSection
EndGlobal
131 changes: 131 additions & 0 deletions Session02/Session03/Session03Exercise02/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System;
using System.Globalization;

namespace Session03Exercise02
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Ange ett antal siffror, separerat med kommatecken.");
var input = Console.ReadLine();
Console.WriteLine();
// Alternativt var inputArray = input.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var inputArray = input.Split(",", StringSplitOptions.RemoveEmptyEntries);

#region min grej
/*
int total = 0;
int loops = 0;
int maxValue = 0;
int minValue = Convert.ToInt32(inputArray[0]);
int testValue;
foreach (var number in inputArray)
{
Console.WriteLine("Värdet är " + number);
testValue = Convert.ToInt32(number);
Copy link
Owner

Choose a reason for hiding this comment

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

Variabelnamnet testvalue blir lite generellt i detta hänseende, fundera på om det finns något ännu tydligare.

if (maxValue < testValue)
{
maxValue = testValue;
}
if (minValue > testValue)
{
minValue = testValue;
}
total += Convert.ToInt32(number);
Copy link
Owner

Choose a reason for hiding this comment

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

Här konverteras number till int ytterligare en gång (som på rad 28).
För att undvika ineffektivitet i koden och att man behöver genomföra ändringar på flera ställen så nyttjar vi på Geta DRY-principen. Här kan man läsa mer om den.
https://en.wikipedia.org/wiki/Don%27t_repeat_yourself

loops++;
}
Console.WriteLine();
Console.WriteLine("Medelvärdet är: " + total/loops);
Console.WriteLine();
Console.WriteLine("Max värdet är: " + maxValue);
Console.WriteLine();
Console.WriteLine("Min värdet är: " + minValue);
*/
#endregion
double? [] array = new double?[inputArray.Length];
#region min andra grej
/*
for (int i = 0; i <inputArray.Length; i++)
{
try
{
array[i] = Convert.ToDouble(inputArray[i]);
}
catch (Exception)
{
array[i] = 0;
Console.WriteLine("Värdet ändrades");
}
}
*/
#endregion
for (int i = 0; i < inputArray.Length; i++)
{
NumberStyles numberStyle = NumberStyles.Integer | NumberStyles.Float;
IFormatProvider formatProvider = CultureInfo.InvariantCulture;
bool parsed = double.TryParse(inputArray[i], numberStyle, formatProvider, out double parsedValue);

if (parsed == true)
{
array[i] = parsedValue;
}
else
{
array[i] = null;
}
#region try catch
/*try
{
array[i] = Convert.ToDouble(inputArray[i]);
}
catch
{
array[i] = null;
}
*/
#endregion
}

double? total = 0;
double? loops = 0;
double? maxValue = 0;
double? minValue = array[0];
double? testValue;

foreach (var number in array)
{
if(number == null)
{
Console.WriteLine("The value is null");
continue;
}
Console.WriteLine("Värdet är " + number);
testValue = number;

if (maxValue < testValue)
{
maxValue = testValue;
}

if (minValue > testValue)
{
minValue = testValue;
}

total += number;
loops++;
}
Console.WriteLine();
Console.WriteLine("Medelvärdet är: " + total / loops);
Console.WriteLine();
Console.WriteLine("Det högsta värdet är: " + maxValue);
Console.WriteLine();
Console.WriteLine("Det minsta värdet är: " + minValue);
}
}
}
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 Session02/Övningar lektion 3/Övningar lektion 3.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}") = "Övningar lektion 3", "Övningar lektion 3\Övningar lektion 3.csproj", "{20FC56F0-46EC-47DD-9079-C7452C7C0C27}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{20FC56F0-46EC-47DD-9079-C7452C7C0C27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20FC56F0-46EC-47DD-9079-C7452C7C0C27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20FC56F0-46EC-47DD-9079-C7452C7C0C27}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20FC56F0-46EC-47DD-9079-C7452C7C0C27}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {96358039-F896-4E90-AFFC-E49A05F34BA1}
EndGlobalSection
EndGlobal
54 changes: 54 additions & 0 deletions Session02/Övningar lektion 3/Övningar lektion 3/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;

namespace Övningar_lektion_3
{
class Program
{
static void Main(string[] args)
{
// Övning 1
/*Console.WriteLine("Input value 1:");
int input1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Input value 2:");
int input2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
for (int i = input1 + 1; i < input2; i++)
{
Console.WriteLine(i);
}
*/
// Övning 2
for (int i = 1; i < 65; i++)
{
int test = i % 2;
int lineBreak = i % 8;
int lineSwitch = 1;

if (lineSwitch % 2 == 1)
{
if (lineBreak == 1)
{
Console.Write("\n");
lineSwitch++;
}
if (test == 1)
Console.Write('▓');
else
Console.Write('░');
}
else if (lineSwitch % 2 == 0)
{
if (lineBreak == 1)
{
Console.Write("\n");
lineSwitch++;
}
if (test == 0)
Console.Write('▓');
else
Console.Write('░');
}
Copy link
Owner

Choose a reason for hiding this comment

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

Bra lösning på problemet!
Se ovan om DRY-principen.

}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Övningar_lektion_3</RootNamespace>
</PropertyGroup>

</Project>