Skip to content
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

Numbers #5

Open
wants to merge 7 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
6 changes: 6 additions & 0 deletions Session01/Session01.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.30406.217
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session01-Example", "Session01-Example\Session01-Example.csproj", "{2E6C3DA5-47A0-4EE6-86E9-EC9977AA7EDC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Session03Excercise02", "..\Session03\Session03\Session03Excercise02\Session03Excercise02.csproj", "{37E89230-3D50-4984-8580-29DD96390236}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{2E6C3DA5-47A0-4EE6-86E9-EC9977AA7EDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E6C3DA5-47A0-4EE6-86E9-EC9977AA7EDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E6C3DA5-47A0-4EE6-86E9-EC9977AA7EDC}.Release|Any CPU.Build.0 = Release|Any CPU
{37E89230-3D50-4984-8580-29DD96390236}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37E89230-3D50-4984-8580-29DD96390236}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37E89230-3D50-4984-8580-29DD96390236}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37E89230-3D50-4984-8580-29DD96390236}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
56 changes: 50 additions & 6 deletions Session03/Session03/Session03Excercise02/Program.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,64 @@
using System;
using System.Diagnostics;
using System.Globalization;

namespace Session03Excercise02
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Ange ett antal siffror, separerat med kommatecken.");
var input = Console.ReadLine();
var inputArray = input.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries);
// Konvertera det inmatade värdena från strängar till siffror
// Resultatet skall presentera:
// Lägsta värdet
// Högsta värdet
// Medelvärde (snitt)
// Programmet skall vara felhanterat
// Felaktiga värden får inte påverka medelvärde, lägsta eller högsta.

foreach (var number in inputArray)
while (true)
{
Console.WriteLine("Värdet är " + number);
}
Console.WriteLine("Ange ett antal siffror, separerat med mellanslag.");
string input = Console.ReadLine();
string[] inputArray = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
double sum = 0;
double highestValue = 0;
double lowestValue = 0;
int countOfNumbers = 0;
double?[] numberArray = new double?[inputArray.Length];

for (int i = 0; i < inputArray.Length; i++)
{
bool parsed = double.TryParse(inputArray[i], out double parsedValue);

if (parsed)
{
highestValue = parsedValue;
lowestValue = parsedValue;
numberArray[i] = parsedValue;
countOfNumbers++;
}
else numberArray[i] = null;

}

foreach (var number in numberArray)
{
if (number != null)
{
sum += (double)number;
foreach (var number2 in numberArray)
{
if ((number > number2) && (number > highestValue)) highestValue = (double)number;
if ((number < number2) && (number < lowestValue)) lowestValue = (double)number;
}
}
}
double average = sum / countOfNumbers;
Console.WriteLine("medelvärde är: " + average);
Console.WriteLine("högsta värde är: " + highestValue);
Console.WriteLine("lägsta värde är: " + lowestValue);
}
}
}
}
55 changes: 55 additions & 0 deletions Session04/Session04/Session04.sln
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.30406.217
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Session04Example", "Session04Example\Session04Example.csproj", "{1FFA0433-A8DD-4A58-9C7D-9AB66B2DA6DE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Session04Example02Errors", "Session04Example02Errors\Session04Example02Errors.csproj", "{49964154-D027-42B6-82CD-15CD1A0E0D10}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Session04Example03Nullable", "Session04Example03Nullable\Session04Example03Nullable.csproj", "{20610575-7925-4528-B7CB-F4ECA5378418}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Session04Example04", "Session04Example04\Session04Example04.csproj", "{BCC55225-BD2F-4552-9DF5-3409E807B98A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Session04Example05", "Session04Example05\Session04Example05.csproj", "{8031DBA2-9DDF-412C-AC7A-DF61697677D3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Session04Example06", "Session04Example06\Session04Example06.csproj", "{EA07DF5C-4E8F-45E7-A999-3C359F88A961}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1FFA0433-A8DD-4A58-9C7D-9AB66B2DA6DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1FFA0433-A8DD-4A58-9C7D-9AB66B2DA6DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1FFA0433-A8DD-4A58-9C7D-9AB66B2DA6DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1FFA0433-A8DD-4A58-9C7D-9AB66B2DA6DE}.Release|Any CPU.Build.0 = Release|Any CPU
{49964154-D027-42B6-82CD-15CD1A0E0D10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{49964154-D027-42B6-82CD-15CD1A0E0D10}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49964154-D027-42B6-82CD-15CD1A0E0D10}.Release|Any CPU.ActiveCfg = Release|Any CPU
{49964154-D027-42B6-82CD-15CD1A0E0D10}.Release|Any CPU.Build.0 = Release|Any CPU
{20610575-7925-4528-B7CB-F4ECA5378418}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20610575-7925-4528-B7CB-F4ECA5378418}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20610575-7925-4528-B7CB-F4ECA5378418}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20610575-7925-4528-B7CB-F4ECA5378418}.Release|Any CPU.Build.0 = Release|Any CPU
{BCC55225-BD2F-4552-9DF5-3409E807B98A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BCC55225-BD2F-4552-9DF5-3409E807B98A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BCC55225-BD2F-4552-9DF5-3409E807B98A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BCC55225-BD2F-4552-9DF5-3409E807B98A}.Release|Any CPU.Build.0 = Release|Any CPU
{8031DBA2-9DDF-412C-AC7A-DF61697677D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8031DBA2-9DDF-412C-AC7A-DF61697677D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8031DBA2-9DDF-412C-AC7A-DF61697677D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8031DBA2-9DDF-412C-AC7A-DF61697677D3}.Release|Any CPU.Build.0 = Release|Any CPU
{EA07DF5C-4E8F-45E7-A999-3C359F88A961}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA07DF5C-4E8F-45E7-A999-3C359F88A961}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA07DF5C-4E8F-45E7-A999-3C359F88A961}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA07DF5C-4E8F-45E7-A999-3C359F88A961}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {585CA636-84BF-420C-A80D-2091EB2C292F}
EndGlobalSection
EndGlobal