-
Notifications
You must be signed in to change notification settings - Fork 34
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
Number app #15
base: master
Are you sure you want to change the base?
Number app #15
Changes from 12 commits
34f7e7d
267216d
0d39cfb
290b3a3
84d8302
b0d1b30
8f97920
fc4a778
f590607
f858912
a75c975
e07ead4
24cda1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Reflection.Metadata.Ecma335; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace ConsoleApp1 | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
bool looping = true; | ||
char answer = 'y'; | ||
while (looping) | ||
{ | ||
Console.WriteLine("Please enter an amount of time in seconds."); | ||
int secondsInput = Convert.ToInt32(Console.ReadLine()); | ||
int hours = secondsInput / 3600; | ||
int secondsRemaining = secondsInput % 3600; | ||
int minutes = secondsRemaining / 60; | ||
secondsRemaining = secondsRemaining % 60; | ||
Console.WriteLine(secondsInput + " seconds equals " + hours + " hours, " + minutes + " minutes and " + secondsRemaining + " seconds."); | ||
Console.WriteLine("Would you like to continue? (y/n)"); | ||
answer = Convert.ToChar(Console.ReadLine()); | ||
if (answer == 'n') { looping = false; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Placera helst logik som följer en
|
||
} | ||
} | ||
} | ||
} |
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> |
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
|
||
namespace MirrorString | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Please enter a word or sentence."); | ||
string input = Console.ReadLine(); | ||
string reversion = ""; | ||
for (int i = input.Length; i > 0; i--) | ||
{ | ||
reversion = String.Concat(reversion, input.Substring(i-1, 1)); | ||
} | ||
Console.WriteLine(reversion); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Denna lösning var påhittig! |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
| ||
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}") = "Session02Excercise02", "Session02Excercise02\Session02Excercise02.csproj", "{1C4E07D7-7280-45F3-9766-E751166FC7AE}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Session02Excercise1", "..\csharp-plus-2020\Session02\Session02\Session02Excercise1\Session02Excercise1.csproj", "{D45F4DF0-7B02-497A-B116-69F734DA6DBC}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Excercise03", "Session02Excercise03\Session02Excercise03.csproj", "{9944D6A5-AFDA-4C3D-9B53-3F873A0791C0}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Excercise04", "Session02Excercise04\Session02Excercise04.csproj", "{D8CF8C53-7DC3-41D7-90D3-3A296A96E840}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Time Converter", "ConsoleApp1\Time Converter.csproj", "{2F43B160-4A87-474A-8E47-3E55AC92C0CE}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MirrorString", "MirrorString\MirrorString.csproj", "{328984CD-7137-4373-8DEF-BCE1276395D5}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1C4E07D7-7280-45F3-9766-E751166FC7AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1C4E07D7-7280-45F3-9766-E751166FC7AE}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1C4E07D7-7280-45F3-9766-E751166FC7AE}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1C4E07D7-7280-45F3-9766-E751166FC7AE}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{D45F4DF0-7B02-497A-B116-69F734DA6DBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{D45F4DF0-7B02-497A-B116-69F734DA6DBC}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{D45F4DF0-7B02-497A-B116-69F734DA6DBC}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{D45F4DF0-7B02-497A-B116-69F734DA6DBC}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{9944D6A5-AFDA-4C3D-9B53-3F873A0791C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{9944D6A5-AFDA-4C3D-9B53-3F873A0791C0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{9944D6A5-AFDA-4C3D-9B53-3F873A0791C0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{9944D6A5-AFDA-4C3D-9B53-3F873A0791C0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{D8CF8C53-7DC3-41D7-90D3-3A296A96E840}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{D8CF8C53-7DC3-41D7-90D3-3A296A96E840}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{D8CF8C53-7DC3-41D7-90D3-3A296A96E840}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{D8CF8C53-7DC3-41D7-90D3-3A296A96E840}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{2F43B160-4A87-474A-8E47-3E55AC92C0CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{2F43B160-4A87-474A-8E47-3E55AC92C0CE}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{2F43B160-4A87-474A-8E47-3E55AC92C0CE}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{2F43B160-4A87-474A-8E47-3E55AC92C0CE}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{328984CD-7137-4373-8DEF-BCE1276395D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{328984CD-7137-4373-8DEF-BCE1276395D5}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{328984CD-7137-4373-8DEF-BCE1276395D5}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{328984CD-7137-4373-8DEF-BCE1276395D5}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {BDAE20EE-D5CF-4207-A2DB-FC294DC8247C} | ||
EndGlobalSection | ||
EndGlobal |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
|
||
namespace Session02Excercise1 | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Hello scrubs"); | ||
Console.WriteLine("Please enter a value:"); | ||
|
||
var integerValue = Convert.ToInt32(Console.ReadLine()); | ||
|
||
Console.WriteLine("Integer's value is: " + integerValue); | ||
|
||
string stringValue = "of Steel"; | ||
|
||
Console.WriteLine("The walls are made " + stringValue); | ||
if (integerValue > 90) | ||
{ | ||
Console.WriteLine(integerValue + " is over 90."); | ||
} | ||
else if (integerValue == 90){ | ||
Console.WriteLine(integerValue + " is equal to 90."); | ||
} | ||
else | ||
{ | ||
Console.WriteLine(integerValue + " is under 90."); | ||
}//enter text here | ||
} | ||
|
||
} | ||
} |
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
|
||
namespace Session02Excercise02 | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Do you want to build a trebuchet? (y/n)"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vem vill inte bygga medeltida belägringsvapen? |
||
string answer = Console.ReadLine(); | ||
|
||
if (answer.ToLower() == "y") | ||
{ | ||
Console.WriteLine("Awesome, let's get started..."); | ||
} | ||
else if (answer.ToLower() == "n") | ||
{ | ||
Console.WriteLine("That's too bad. Maybe another time."); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Input not recognized, please try again."); | ||
} | ||
int userInput = 0; | ||
Console.WriteLine("If you want to escape the loop, guess the number between 1 and 50."); | ||
while(userInput != 23) | ||
{ | ||
userInput = Convert.ToInt32(Console.ReadLine()); | ||
if (userInput < 23) | ||
{ | ||
Console.WriteLine("Too low, try again."); | ||
} | ||
else if (userInput > 23) | ||
{ | ||
Console.WriteLine("Too high, try again."); | ||
} | ||
} | ||
Console.WriteLine("Congratulations, you've escaped the loop."); | ||
} | ||
} | ||
} |
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
|
||
namespace Session02Excercise03 | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var additionResult = 1 + 2; | ||
var incrementResult = additionResult++; | ||
|
||
Console.WriteLine("Addition Result: " + additionResult + " and Increment Result: " + incrementResult); | ||
|
||
var trueValue = true; | ||
var falseValue = false; | ||
var andResult = trueValue & falseValue; | ||
var orResult = trueValue | falseValue; | ||
var xorResult = trueValue ^ falseValue; | ||
|
||
Console.WriteLine("andResult is " + andResult + " while orResult is " + orResult + " and xorResult is " + xorResult); | ||
|
||
var moduloResult = 3 % 2; | ||
Console.WriteLine("ModuloResult is " + moduloResult); | ||
|
||
int highInteger = 1000; | ||
var divisionResult = highInteger / 3; | ||
Console.WriteLine("divisionResult is " + divisionResult); | ||
|
||
int higherInteger = 10000; | ||
var doubleDivisionResult = highInteger / 3.0; | ||
Console.WriteLine("doubleDivisionResult is " + doubleDivisionResult); | ||
|
||
int forcedIntDivisionResult = (int)(highInteger / 3.0); | ||
Console.WriteLine("forcedIntDivisionResult is equal to " + forcedIntDivisionResult); | ||
|
||
var conversionResult = Convert.ToInt32(doubleDivisionResult); | ||
Console.WriteLine("conversionResult is " + conversionResult); | ||
|
||
var midpointDivisionResult = 1.0 / 2.0; | ||
Console.WriteLine("midPointDivisionResult is " + midpointDivisionResult); | ||
Console.WriteLine("castToInt " + ((int)(midpointDivisionResult)).ToString()); | ||
Console.WriteLine("Math.Ceiling " + Math.Ceiling(midpointDivisionResult)); | ||
Console.WriteLine("Math.Floor" + Math.Floor(midpointDivisionResult)); | ||
Console.WriteLine("Math.Round" + Math.Round(midpointDivisionResult, 3)); | ||
|
||
Console.WriteLine("additionResult is currently: " + additionResult); | ||
additionResult += 2; | ||
Console.WriteLine("additionResult is currently: " + additionResult); | ||
//Also, these work | ||
additionResult -= 2; | ||
Console.WriteLine("additionResult is currently: " + additionResult); | ||
additionResult *= 2; | ||
Console.WriteLine("additionResult is currently: " + additionResult); | ||
additionResult /= 2; | ||
Console.WriteLine("additionResult is currently: " + additionResult); | ||
|
||
var greaterResult = 5 > 3; | ||
Console.WriteLine("Is five really greater than three? Of course it's " + greaterResult); | ||
|
||
var lessThanResult = 5 < 3; | ||
Console.WriteLine("Is five less than three? You can bet that it is " + lessThanResult); | ||
|
||
//And there's two more | ||
var greaterOrEqual = 3 >= 3; | ||
var lessOrEqual = 5 <= 5; | ||
Console.WriteLine("Is three greater or equal to three? It's " + greaterOrEqual + " And of course is five less than or equal to five? " + lessOrEqual); | ||
|
||
var andOperationResult = true && false; | ||
var orOperationResult = false || false; | ||
|
||
Console.WriteLine("andOperationResult " + andOperationResult); | ||
Console.WriteLine("orOperationResult" + orOperationResult); | ||
|
||
} | ||
} | ||
} |
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
|
||
namespace Session02Excercise04 | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Please enter an integer."); | ||
var input = Console.ReadLine(); | ||
var integer = Convert.ToInt32(input); | ||
if (integer >= 18) | ||
{ | ||
Console.WriteLine("The number you entered is greater than or equal to 18."); | ||
} | ||
else if (integer >=10 && integer <18) | ||
{ | ||
Console.WriteLine("The number you entered is between 10 and 17."); | ||
} | ||
else if (integer >= 7 && integer <10) | ||
{ | ||
Console.WriteLine("The number you entered is between 7 and 9."); | ||
} | ||
else if (integer >=2 && integer <7) | ||
{ | ||
Console.WriteLine("The number you enetered is between 2 and 6."); | ||
svenrog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
else | ||
{ | ||
Console.WriteLine("The number you entered is less than 2."); | ||
} | ||
|
||
|
||
Console.WriteLine("Ange temperatur i grader C:"); | ||
var temp = Console.ReadLine(); | ||
var tempInt = Convert.ToInt32(temp); | ||
string waterLabel; | ||
|
||
if (tempInt >= 27) | ||
{ | ||
waterLabel = "Går att bada"; | ||
} | ||
else { | ||
waterLabel = "Fel temperatur."; | ||
} | ||
Console.WriteLine(waterLabel); | ||
//ALternativ | ||
string waterLabelAlt = integer >= 27 ? "Går att bada" : "Går inte att bada"; | ||
Console.WriteLine(waterLabelAlt); | ||
|
||
switch (integer) | ||
{ | ||
case 1: waterLabel = "Går inte att bada alls."; break; | ||
case -3: waterLabel = "Det är 3 minusgrader."; break; | ||
default: /* Vad som händer ifall inget annat träffar*/ break; | ||
} | ||
|
||
|
||
} | ||
} | ||
} |
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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Toppen, kul att se lösningen!
Den här koden skulle må bra av några tomma rader, här och var, för läsbarhetens skull.
För kompakt text gör det svårare att hitta specifika stycken.
Prova tex innan och efter
Console
-anrop.