hey,
ich hab ein Problem mit einem selbsterstellten Programm das nicht das macht was es soll. WIe ihr vielleicht erkennt bin ich kein Informatik - Genie, weil ich des Fach noch nicht allzu lang habe.
Die Aufgabe war ein Programm zu erstellen, mit einem Feld, das 60 nach unten geht und 80 nach rechts.
Es simliert das sickern von Öl bei einer gewissen Wahrscheinlichkeit in die Spalte darunter in der Form. ( 1 = betroffenes Feld, 0 = kein Öl) Das Öl sickert immer nur nach links unten oder rechts unten, nicht direkt.
DIe Prozentzahl steht für die selbstgewählte Chance für das versickern des Öls.
Das Öl "startet " in der obersten Zeile des Feldes in den mittleren 50%. ( Con 1 - 19 kein Öl, von 20 + 50 Öl, von 60 - 79 kein Öl).
Hier nun das Programm
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int p = 0, n = 0 , a = 20, b = 0, c = 1, d = 1, e = 0, f = 0, h = 0, i = 0, j = 0, x = 0, y = 0, z = 0;
int[,] feld = new int[60, 80];
// alles 0 setzen
while ((p <= 59 && n <= 79))
{
feld[p, n] = 0;
p = p + 1;
if (n == 79)
{
n = n + 1;
}
}
// Öl in der ersten Zeile
while (a <= 59)
{
feld[0, a] = 1;
a = a + 1;
}
Console.WriteLine("Mit welcher Prozentzahl soll das Öl durchsickern? ( Zwischen 1 u 100)");
b = Convert.ToInt32(Console.ReadLine());
// Sickern
while ((c <= 59 && d <= 79))
{
if ((d - 1) <= 0)
{
feld[c, d] = 0;
}
else
{
h = c - 1;
i = d - 1;
j = d + 1;
if (feld[h, i] == 1)
{
e = 1;
}
else
{
e = 0;
}
if (feld[h, j] == 1)
{
f = 1;
}
else
{
f = 0;
}
}
if (e == 1)
{
Random zufall = new Random();
int zz = zufall.Next(1, 100);
if (zz <= b)
{
feld[c, d] = 1;
}
}
if (f == 1)
{
Random zufall = new Random();
int zz = zufall.Next(1, 100);
if (zz <= b)
{
feld[c, d] = 1;
}
}
c = c + 1;
d = d + 1;
e = 0;
f = 0;
}
while ((x <= 59))
{
Console. WriteLine("Anzahl der betroffenen Plätze in Zeile " + x);
while (y <= 79)
{
if (feld[x, y] == 1)
{
z = z + 1;
}
y = y + 1;
}
x = x + 1;
Console.WriteLine(z);
}
Console.ReadLine();
}
}
}
Das Problem ist dass egal bei welcher Prozentzahl immer in jeder Zeile die Ahnzahl der betroffenen Felder 40 ist, was ja schlecht sein kann.
Vielen dank für alle Hilfen. Bin echt am verweifeln weil ich das Programm dringend brauch.
Edit: sry für den Grammatikfehler in der Überschrift