Gjett tallet

This commit is contained in:
Geir Okkenhaug Jerstad 2024-11-20 10:31:21 +01:00
parent acfaf64564
commit 3118086163
3 changed files with 69 additions and 0 deletions

View file

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GjettTallet", "GjettTallet.csproj", "{8F821DAD-9CB9-4746-A2FE-C417EAF0B223}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8F821DAD-9CB9-4746-A2FE-C417EAF0B223}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F821DAD-9CB9-4746-A2FE-C417EAF0B223}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F821DAD-9CB9-4746-A2FE-C417EAF0B223}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F821DAD-9CB9-4746-A2FE-C417EAF0B223}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,43 @@
using System;
namespace GjettTallet
{
class Program
{
static void Main(string[] args)
{
var rnd = new Random();
int tilfeldigTall = rnd.Next(1, 100);
bool running = true;
var størreEllerMindre = "Du har ikke valgt et tall ennå";
while (running == true)
{
Console.WriteLine($"{størreEllerMindre}");
Console.WriteLine("Gjett ett tall mellom 1 - 100: ");
var gjettetTallString = Console.ReadLine();
int gjettetTall;
int.TryParse(gjettetTallString, out gjettetTall);
if (gjettetTall == 0)
{
størreEllerMindre = "Enten 0 eller ikke ett tall";
Console.Clear();
}
else if (tilfeldigTall == gjettetTall)
{
Console.WriteLine("Du har gjettet riktig tall");
running = false;
}
else if (tilfeldigTall > gjettetTall)
{
størreEllerMindre = $"Det riktige tallet er høyere, ditt siste tall var: {gjettetTall}";
Console.Clear();
}
else if (tilfeldigTall < gjettetTall)
{
størreEllerMindre = $"Det riktige tallet er lavere, ditt siste tall var: {gjettetTall}";
Console.Clear();
}
}
}
}
}