-
Notifications
You must be signed in to change notification settings - Fork 0
/
FuelCalculator.cs
125 lines (117 loc) · 4.33 KB
/
FuelCalculator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*------------------------------------------------------------------------------
* HTBLA-Leonding / Class: 3ACIF
*------------------------------------------------------------------------------
* Jan Ritt
*------------------------------------------------------------------------------
* Description: The program reads in the fueltype, the driven km and outputs
* the average fuel amount (calculated to average on 100km)
* And tells you if your car uses too much, average or high
* amounts of fuel.
*------------------------------------------------------------------------------
*/
using System;
using System.Text;
namespace FuelCalculator
{
internal class Program
{
static void Main(string[] args)
{
string fuelType, inputKm, inputGasolineAmount;
double km = 0, gasolineAmount = 0;
double averageConsumption;
string formattedAverageConsumption;
bool abort = false;
// Eingabe (E) -- Header
Console.Clear();
Console.Write("\n Fuel Calculator:\n");
Console.Write("==================\n");
// Eingabe (E) -- Input Fuel + Check
Console.Write(" Welchen Kraftstoff tanken Sie (Diesel/Benzin)? ");
fuelType = Console.ReadLine();
if ((fuelType != "Diesel") && (fuelType != "Benzin"))
{
abort = true;
}
// Eingabe (E) -- Input km + Check
if (abort == false)
{
Console.Write(" Wie viele Kilometer sind Sie gefahren? ");
inputKm = Console.ReadLine();
if (double.TryParse(inputKm, out km))
{
if (km <= 0)
{
abort = true;
}
}
else
{
abort = true;
}
}
// Eingabe (E) -- Input Gasoline Amount + Check
if (abort == false)
{
Console.Write(" Wie viele Liter Kraftstoff haben Sie getankt? ");
inputGasolineAmount = Console.ReadLine();
if (double.TryParse(inputGasolineAmount, out gasolineAmount))
{
if (gasolineAmount <= 0)
{
abort = true;
}
}
else
{
abort = true;
}
}
// Verarbeitung (V) -- Calculate
if (abort == false)
{
Console.Write("--------------------------------------------\n");
averageConsumption = Convert.ToDouble(gasolineAmount / km * 100);
formattedAverageConsumption = averageConsumption.ToString("0.00");
Console.Write($" Der errechnete Durchschnittsverbrauch ist {formattedAverageConsumption} pro 100km.\n");
// Verarbeitung (V) -- Calculate Diesel
if ((fuelType == "Diesel") && (averageConsumption < 5))
{
Console.Write(" Ihr Auto ist sparsam!\n");
}
else if ((fuelType == "Diesel") && (averageConsumption >= 5) && (averageConsumption <= 6))
{
Console.Write(" Ihr Auto ist im Normalbereich!\n");
}
else if ((fuelType == "Diesel") && (averageConsumption > 6))
{
Console.Write(" Ihr Auto braucht zu viel!\n");
}
// Verarbeitung (V) -- Calculate Benzin
if ((fuelType == "Benzin") && (averageConsumption < 6))
{
Console.Write(" Ihr Auto ist sparsam!\n");
}
else if ((fuelType == "Benzin") && (averageConsumption >= 6) && (averageConsumption <= 7))
{
Console.Write(" Ihr Auto ist im Normalbereich!\n");
}
else if ((fuelType == "Benzin") && (averageConsumption > 7))
{
Console.Write(" Ihr Auto braucht zu viel!\n");
}
}
// Ausgabe (A) -- Output The Fail-message
if (abort == true)
{
Console.Write("--------------------------------------------\n");
Console.Write(" ! Ungültige Eingabe !\n");
Console.Write("--------------------------------------------\n");
}
// Ausgabe (A) -- End
Console.Write("\n Weiter mit beliebiger Taste ...\n");
Console.ReadKey();
Console.Clear();
}
}
}