Skip to content
Snippets Groups Projects
Commit c20bc7bc authored by Uwe Wienkop's avatar Uwe Wienkop
Browse files

Woche 2: Eingaben, Ausgaben, Fallunterscheidungen

parent b1f17584
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,7 @@ namespace _01_Pythagoras
Console.Write("Länge der Seite b: ");
b = Convert.ToDouble(Console.ReadLine());
Console.WriteLine($"Länge der Seite c: {Math.Sqrt(a * a + b * b)}");
Console.WriteLine($"Länge der Seite c: {Math.Sqrt(a * a + b + b)} cm");
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_02_Ausgabeformatierung</RootNamespace>
</PropertyGroup>
</Project>
using System;
namespace _02_Ausgabeformatierung
{
class Program
{
static void Main(string[] args)
{
double a = 1234.56789;
a = Convert.ToDouble(Console.ReadLine());
//Normale Ausgabe
Console.WriteLine($"Der Wert von a ist: >{a}<");
////Ausgabe verwendet 14 Stellen, rechtsbündig formatiert
Console.WriteLine($">{a,14}<");
////Ausgabe verwendet 14 Stellen, linksbündig formatiert
Console.WriteLine($">{a,-14}<");
////Ausgabe wird auf zwei Stellen gerundet
Console.WriteLine($">{a:f2}<");
////Ausgabe wird auf drei Stellen gerundet und rechtsbündig innerhalb von 14 Stellen ausgegeben
Console.WriteLine($">{a,14:f3}<");
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_02_Fallunterscheidungen</RootNamespace>
</PropertyGroup>
</Project>
using System;
namespace _02_Fallunterscheidungen
{
class Program
{
static void Main(string[] args)
{
int x = 5, y = 3;
int kleiner;
if (x < y)
{
kleiner = x;
}
else
{
kleiner = y;
}
Console.WriteLine($"Die kleinere Zahl ist {kleiner}");
if (x == 3)
Console.WriteLine("x ist drei");
else if (x == 4)
Console.WriteLine("x ist vier");
else if (x == 5)
Console.WriteLine("x ist fünf");
else
Console.WriteLine("Falsche Auswahl");
// Temperaturauswahl
// t < 0 --> ganz schön kalt
// t > 24 --> Summertime
// sonst --> weder warm noch kalt
// Tests: <0, 0..24, 25 ...
// Richtige Lösung
int t = -5;
if (t < 0)
Console.WriteLine("ganz schön kalt");
else if (t > 24)
Console.WriteLine("Summertime");
else
Console.WriteLine("weder warm noch kalt");
Console.WriteLine("-----------");
// Fehlerhafter Lösungsversuch
// Bei negativer Temperatur gibt es zwei Ausgaben
t = -5;
if (t < 0)
Console.WriteLine("ganz schön kalt");
if (t > 24)
Console.WriteLine("Summertime");
else
Console.WriteLine("weder warm noch kalt");
Console.WriteLine("-----------");
// Richtige Lösung
// ABER vergleichsweise viele Vergleiche
t = -5;
if (t < 0)
Console.WriteLine("ganz schön kalt");
if (t >= 0 && t <= 24)
Console.WriteLine("weder warm noch kalt");
if (t >24 )
Console.WriteLine("Summertime");
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_02_Rechteck</RootNamespace>
</PropertyGroup>
</Project>
using System;
namespace _02_Rechteck
{
class Program
{
static void Main(string[] args)
{
// 1. Variablendeklaration
double a, b;
//double flaeche;
Console.WriteLine("Rechteck Berechnung:");
// 2. Werte abfragen und in Gleitkomma konvertieren
Console.WriteLine("Wert für Seitenlänge a eingeben: ");
a = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Wert für Seitenlänge b eingeben: ");
b = Convert.ToDouble(Console.ReadLine());
// 3. Fläche berechnen
//a = a + 2;
double flaeche;
flaeche = a * b;
// 4. Fläche ausgeben
Console.WriteLine($"Die Fläche des Rechtecks beträgt: {flaeche}");
// a = 2 + 3 * Math.Sin(Math.Sqrt(25));
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_02_Rechteck_Di</RootNamespace>
</PropertyGroup>
</Project>
using System;
namespace _02_Rechteck_Di
{
class Program
{
static void Main(string[] args)
{
// 1. Variable benennen (Seitenlängen, Fläche)
double a, b, flaeche;
// 2. Titel (Fläche Rechteck) ausgeben
Console.WriteLine("Berechnung der Fläche eines Rechtecks");
// 3. Ausgabe Seitenlänge a
// 4. Eingabe Zahl, inkl. Konvertierung
Console.Write("Länge der Seite a: ");
string eingabe = Console.ReadLine();
a = Convert.ToDouble(eingabe);
// 4. dto. für Seite b
Console.Write("Länge der Seite b: ");
b = Convert.ToDouble(Console.ReadLine());
// 5. Fläche berechnen
flaeche = a * b;
// 6. Ergebnis ausgeben
Console.WriteLine($"Die Fläche des Rechtecks mit den Seitenlängen {a}cm und {b}cm beträgt: {flaeche}cm");
}
}
}
......@@ -5,7 +5,15 @@ VisualStudioVersion = 16.0.31702.278
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "01 Pythagoras", "01 Pythagoras\01 Pythagoras.csproj", "{8DC7B6AA-65FE-46EA-B91C-245660F723E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "01 Hallo", "01 Hallo\01 Hallo.csproj", "{DF891CC9-9677-471D-BE07-0B9C679534AB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "01 Hallo", "01 Hallo\01 Hallo.csproj", "{DF891CC9-9677-471D-BE07-0B9C679534AB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "02 Rechteck", "02 Rechteck\02 Rechteck.csproj", "{76322CB6-249B-428C-9847-E551E25F38DB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "02 Rechteck_Di", "02 Rechteck_Di\02 Rechteck_Di.csproj", "{857CABA6-FCAE-4E48-8357-02B08F87BE49}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "02 Ausgabeformatierung", "02 Ausgabeformatierung\02 Ausgabeformatierung.csproj", "{27FA1463-A81B-46A4-A331-457D973BA70C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "02 Fallunterscheidungen", "02 Fallunterscheidungen\02 Fallunterscheidungen.csproj", "{3370BE4E-7EF8-4ABB-949D-62CA9FA5CDA7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -21,6 +29,22 @@ Global
{DF891CC9-9677-471D-BE07-0B9C679534AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DF891CC9-9677-471D-BE07-0B9C679534AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DF891CC9-9677-471D-BE07-0B9C679534AB}.Release|Any CPU.Build.0 = Release|Any CPU
{76322CB6-249B-428C-9847-E551E25F38DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{76322CB6-249B-428C-9847-E551E25F38DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76322CB6-249B-428C-9847-E551E25F38DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76322CB6-249B-428C-9847-E551E25F38DB}.Release|Any CPU.Build.0 = Release|Any CPU
{857CABA6-FCAE-4E48-8357-02B08F87BE49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{857CABA6-FCAE-4E48-8357-02B08F87BE49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{857CABA6-FCAE-4E48-8357-02B08F87BE49}.Release|Any CPU.ActiveCfg = Release|Any CPU
{857CABA6-FCAE-4E48-8357-02B08F87BE49}.Release|Any CPU.Build.0 = Release|Any CPU
{27FA1463-A81B-46A4-A331-457D973BA70C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27FA1463-A81B-46A4-A331-457D973BA70C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27FA1463-A81B-46A4-A331-457D973BA70C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27FA1463-A81B-46A4-A331-457D973BA70C}.Release|Any CPU.Build.0 = Release|Any CPU
{3370BE4E-7EF8-4ABB-949D-62CA9FA5CDA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3370BE4E-7EF8-4ABB-949D-62CA9FA5CDA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3370BE4E-7EF8-4ABB-949D-62CA9FA5CDA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3370BE4E-7EF8-4ABB-949D-62CA9FA5CDA7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment