From 95d3a2be13477a89ed2058d38d0d22221cd7ee5d Mon Sep 17 00:00:00 2001 From: Geir Okkenhaug Jerstad Date: Thu, 14 Nov 2024 14:08:38 +0100 Subject: [PATCH] RND --- Emne 3/ConsoleApp4/IfElse/Program.cs | 33 ++++++++++++++++++++++++- Emne 3/ConsoleApp5/ConsoleApp5.sln | 16 ++++++++++++ Emne 3/ConsoleApp5/Random/Program.cs | 24 ++++++++++++++++++ Emne 3/ConsoleApp5/Random/Random.csproj | 10 ++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 Emne 3/ConsoleApp5/ConsoleApp5.sln create mode 100644 Emne 3/ConsoleApp5/Random/Program.cs create mode 100644 Emne 3/ConsoleApp5/Random/Random.csproj diff --git a/Emne 3/ConsoleApp4/IfElse/Program.cs b/Emne 3/ConsoleApp4/IfElse/Program.cs index db114ed..0709f3e 100644 --- a/Emne 3/ConsoleApp4/IfElse/Program.cs +++ b/Emne 3/ConsoleApp4/IfElse/Program.cs @@ -6,6 +6,13 @@ private static int num2 = 10; private static bool IsEqual = false; static void Main(string[] args) + { + Compare(); + UnEqual(5, 5); + IsThirty(25, 5); + } + + static void Compare() { if (num == num2) { @@ -17,7 +24,7 @@ Console.WriteLine("Not Equal"); IsEqual = false; } - + if (IsEqual) { num++; @@ -29,6 +36,30 @@ Console.WriteLine(num); } } + + static int UnEqual(int num1, int num2) + { + if (num1 != num2) + { + return num1 + num2; + } + else + { + return num1 * num2; + } + } + + static bool IsThirty(int num, int num2) + { + if (num + num2 == 30) + { + return true; + } + else + { + return false; + } + } } } diff --git a/Emne 3/ConsoleApp5/ConsoleApp5.sln b/Emne 3/ConsoleApp5/ConsoleApp5.sln new file mode 100644 index 0000000..30a6bb2 --- /dev/null +++ b/Emne 3/ConsoleApp5/ConsoleApp5.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Random", "Random\Random.csproj", "{94A6C03C-25AE-4D33-97EB-E732F895D396}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {94A6C03C-25AE-4D33-97EB-E732F895D396}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {94A6C03C-25AE-4D33-97EB-E732F895D396}.Debug|Any CPU.Build.0 = Debug|Any CPU + {94A6C03C-25AE-4D33-97EB-E732F895D396}.Release|Any CPU.ActiveCfg = Release|Any CPU + {94A6C03C-25AE-4D33-97EB-E732F895D396}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Emne 3/ConsoleApp5/Random/Program.cs b/Emne 3/ConsoleApp5/Random/Program.cs new file mode 100644 index 0000000..1bb970e --- /dev/null +++ b/Emne 3/ConsoleApp5/Random/Program.cs @@ -0,0 +1,24 @@ +using System; +namespace Random +{ + class Random + { + static void Main(string[] args) + { + System.Random rnd = new System.Random(); + int randomnr = rnd.Next(0, 3); + if (randomnr == 0) + { + Console.WriteLine("Tallet ble 0"); + }else if (randomnr == 1) + { + Console.WriteLine("Tallet ble 1"); + } + else + { + Console.WriteLine("Tallet ble 2"); + } + } + } + +} \ No newline at end of file diff --git a/Emne 3/ConsoleApp5/Random/Random.csproj b/Emne 3/ConsoleApp5/Random/Random.csproj new file mode 100644 index 0000000..2f4fc77 --- /dev/null +++ b/Emne 3/ConsoleApp5/Random/Random.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + +