Das ist die 1. (lange) Form

1. Form
Es soll so wie hier aussehen...
Das ist die 2. Form (das genau gleiche Programm) und ist stark gekürzt.

2. Form
Wie kriege ich das jetzt so hin, wie beim oberen Bild?
Code:
int zahl1, zahl2, zahl3, zahl4, zahl5, zahl6, zahl7;
string nochmal;
Console.WriteLine("Dieses Computer-Programm kann Gedanken lesen.");
Console.WriteLine("Es kann jede Zahl zwischen 0 und 127 erraten, die du dir merkst.");
Console.WriteLine("Das Einzige, was du machen musst, ist mit <j> zu antworten, wenn deine Zahl in der vom Programm aufgelisteten Zahlen dabei ist.");
Console.WriteLine("Anstonsten antworte mit <n>.");
Console.WriteLine("-----------------------------------------------");
nochmal = ("j");
while (nochmal == "j")
{
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("Also, merke dir die Zahl zwischen 0 und 127 und drücke danach die <enter>-Taste.");
Console.ReadKey();
//Definition des 1. Bildschirm
int[] zahlen1 = { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127 };
for (int i = 0; i < zahlen1.Length; i++)
{
Console.Write(zahlen1[i] + "\t");
if ((i + 1) % 8 == 0)
{
Console.WriteLine("");
Console.WriteLine("");
}
}
Console.WriteLine("");
Console.WriteLine("Ist deine Zahl in der Auflistung dabei? <j/n>");
string antwort1 = Console.ReadLine();
if (antwort1 == "j")
{
zahl1 = 1;
}
else
{
zahl1 = 0;
}
//Definition des 2. Bildschirm
int[] zahlen2 = { 2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31, 34, 35, 38, 39, 42, 43, 46, 47, 50, 51, 54, 55, 58, 59, 62, 63, 66, 67, 70, 71, 74, 75, 78, 79, 82, 83, 86, 87, 90, 91, 94, 95, 98, 99, 102, 103, 106, 107, 110, 111, 114, 115, 118, 119, 122, 123, 126, 127 };
for (int l = 0; l < zahlen2.Length; l++)
{
Console.Write(zahlen2[l] + "\t");
if ((l + 1) % 8 == 0)
{
Console.WriteLine("");
Console.WriteLine("");
}
}
Console.WriteLine("");
Console.WriteLine("Ist deine Zahl in der Auflistung dabei? <j/n>");
string antwort2 = Console.ReadLine();
if (antwort2 == "j")
{
zahl2 = 2;
}
else
{
zahl2 = 0;
}
//Definition des 3. Bildschirm
int[] zahlen3 = { 4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30, 31, 36, 37, 38, 39, 44, 45, 46, 47, 52, 53, 54, 55, 60, 61, 62, 63, 68, 69, 70, 71, 76, 77, 78, 79, 84, 85, 86, 87, 92, 93, 94, 95, 100, 101, 102, 103, 108, 109, 110, 111, 116, 117, 118, 119, 124, 125, 126, 127 };
for (int k = 0; k < zahlen3.Length; k++)
{
Console.Write(zahlen3[k] + "\t");
if ((k + 1) % 8 == 0)
{
Console.WriteLine("");
Console.WriteLine("");
}
}
Console.WriteLine("");
Console.WriteLine("Ist deine Zahl in der Auflistung dabei? <j/n>");
string antwort3 = Console.ReadLine();
if (antwort3 == "j")
{
zahl3 = 4;
}
else
{
zahl3 = 0;
}
//Definition des 4. Bildschirm
int[] zahlen4 = { 8, 9, 10, 11, 12, 13, 14, 15, 24, 25, 26, 27, 28, 29, 30, 31, 40, 41, 42, 43, 44, 45, 46, 47, 56, 57, 58, 59, 60, 61, 62, 63, 72, 73, 88, 89, 90, 91, 92, 93, 94, 95, 104, 105, 106, 107, 108, 109, 110, 111, 11, 120, 121, 122, 123, 124, 125, 126, 127 };
for (int l = 0; l < zahlen4.Length; l++)
{
Console.Write(zahlen4[l] + "\t");
if ((l + 1) % 8 == 0)
{
Console.WriteLine("");
Console.WriteLine("");
}
}
Console.WriteLine("");
Console.WriteLine("Ist deine Zahl in der Auflistung dabei? <j/n>");
string antwort4 = Console.ReadLine();
if (antwort4 == "j")
{
zahl4 = 8;
}
else
{
zahl4 = 0;
}
//Definition des 5. Bildschirm
int[] zahlen5 = { 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127 };
for (int m = 0; m < zahlen5.Length; m++)
{
Console.Write(zahlen5[m] + "\t");
if ((m + 1) % 8 == 0)
{
Console.WriteLine("");
Console.WriteLine("");
}
}
Console.WriteLine("");
Console.WriteLine("Ist deine Zahl in der Auflistung dabei? <j/n>");
string antwort5 = Console.ReadLine();
if (antwort5 == "j")
{
zahl5 = 16;
}
else
{
zahl5 = 0;
}
//Definition des 6. Bildschirm
int[] zahlen6 = { 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, 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, 126, 127 };
for (int n = 0; n < zahlen6.Length; n++)
{
Console.Write(zahlen6[n] + "\t");
if ((n + 1) % 8 == 0)
{
Console.WriteLine("");
Console.WriteLine("");
}
}
Console.WriteLine("");
Console.WriteLine("Ist deine Zahl in der Auflistung dabei? <j/n>");
string antwort6 = Console.ReadLine();
if (antwort6 == "j")
{
zahl6 = 32;
}
else
{
zahl6 = 0;
}
//Definition des 7. Bildschirm
int[] zahlen7 = { 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, 126, 127 };
for (int o = 0; o < zahlen7.Length; o++)
{
Console.Write(zahlen7[o] + "\t");
if ((o + 1) % 8 == 0)
{
Console.WriteLine("");
Console.WriteLine("");
}
}
Console.WriteLine("");
Console.WriteLine("Ist deine Zahl in der Auflistung dabei? <j/n>");
string antwort7 = Console.ReadLine();
if (antwort7 == "j")
{
zahl7 = 64;
}
else
{
zahl7 = 0;
}
//Ausrechnung der gemerkten Zahl
int errateneZahl = zahl1 + zahl2 + zahl3 + zahl4 + zahl5 + zahl6 + zahl7;
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("----------------------------------");
Console.WriteLine("Du hast dir die Zahl {0} gemerkt!!", errateneZahl);
Console.WriteLine("----------------------------------");
Console.WriteLine("");
Console.WriteLine("Willst du es noch einmal mit einer anderen Zahl versuchen? (j/n)");
nochmal = Console.ReadLine();

1. Form
Es soll so wie hier aussehen...
Das ist die 2. Form (das genau gleiche Programm) und ist stark gekürzt.
Code:
string nochmal;
Console.WriteLine("Dieses Computer-Programm kann Gedanken lesen.");
Console.WriteLine("Es kann jede Zahl zwischen 0 und 127 erraten, die du dir merkst.");
Console.WriteLine("Das Einzige, was du machen musst, ist mit <j> zu antworten, wenn deine Zahl in der vom Programm aufgelisteten Zahlen dabei ist.");
Console.WriteLine("Anstonsten antworte mit <n>.");
Console.WriteLine("-----------------------------------------------");
nochmal = ("j");
while (nochmal == "j")
{
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("Also, merke dir die Zahl zwischen 0 und 127 und drücke danach die <enter>-Taste.");
Console.ReadKey();
//Definition des 1. Bildschirm
int errateneZahl = 0;
for (int i = 0; i < 7; ++i)
{
int mask = 1 << i;//Maske erstellen
//Die erste Abfrage, Zahlenausgabe
for (int value = 1; value <= 127; value++)
{
//Prüfen, ob Bit0 gesetzt ist
if ((value & mask) != 0)
{//Bit gesetzt, die Zahl kann angezeigt werden
Console.Write(value + "\t");
}
}
Console.WriteLine("");
Console.WriteLine("Ist deine Zahl in der Auflistung dabei? <j/n>");
var antwort = Console.ReadLine();
if (antwort == "j")
{
errateneZahl += (int)Math.Pow(2, i);//Zahl entsprechend drauf addieren
}
}
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("----------------------------------");
Console.WriteLine("Du hast dir die Zahl {0} gemerkt!!", errateneZahl);
Console.WriteLine("----------------------------------");
Console.WriteLine("");
Console.WriteLine("Willst du es noch einmal mit einer anderen Zahl versuchen? (j/n)");
nochmal = Console.ReadLine();

2. Form
Wie kriege ich das jetzt so hin, wie beim oberen Bild?
Zuletzt bearbeitet: