Hab das Teil mal in C# geschrieben bin aba noch anfänger mein prog stil ist vllt noch net so toll
Is aba ohne diese Berechnung der versuche und dieser Chance
Code:
using System;
namespace Lottotip
{
class MainClass
{
public static void Main(string[] args)
{
ConsoleKeyInfo ci;
Random r= new Random();
int[] zahlen = new int[6];
int tmp,i,zahl,k=0,l=0,ct=0,vs=0,j;
string eng;
int[] lotto = new int[50];
int[] engg = new int[100];
int[] enggg = new int[6];
do{
k=0;l=0;
for(i=0; i<zahlen.Length;i++){
tmp = r.Next(1,49)+1;
if(Array.IndexOf(zahlen, tmp)==-1){
zahlen[i] = tmp;
}
}
Array.Sort(zahlen);
Array.Clear(engg,0,engg.Length);
Array.Clear(lotto,0,lotto.Length);
for(i = 0;i < zahlen.Length;i++){
try{
Console.Write("Geben sie die "+(i+1)+".te Zahl ein:");
eng=Console.ReadLine();
zahl=Convert.ToInt32(eng);
enggg[i]=zahl;
if(Array.IndexOf(engg,zahl)!=-1){
Console.WriteLine("Die Zahl wurde schon eingegeben");
i--;
}
if(zahl<=0 || zahl>=50){
Console.WriteLine("Die zahl muss zwischen 1 und 49 liegen");
i--;
}
foreach(int z1 in zahlen){
if(z1==zahl)lotto[z1]=enggg[i];
}
k++;
engg[k]=zahl;
}
catch(OverflowException){
Console.WriteLine("Die zahl muss zwischen 1 und 49 liegen");
i--;
}
catch(FormatException){
Console.WriteLine("Sie Haben keine Zahl Eingegeben");
i--;
}
}
Array.Sort(enggg);
Console.WriteLine("Die Lotto zahlen sind");
foreach(int z in zahlen)Console.Write(z+" ");
Console.WriteLine("\nDeine Eingabe War");
for(i=0;i<enggg.Length; i++){
Console.Write(enggg[i]+" ");
}
Array.Clear(engg,0,engg.Length);
foreach(int z in enggg){
if(Array.IndexOf(lotto,z)!=-1){
engg[l]=z;
l++;
}
}
Console.WriteLine("\nSie Haben "+l+" Übereinstimmungen");
for(i=0; i< l;i++){
Console.Write("Zahl "+(i+1)+": "+engg[i]+" ");
}
Console.WriteLine("\nWollen sie es noch einmal versuchen ?<j>");
ci=Console.ReadKey(true);
}while(Char.ToUpper(ci.KeyChar)=='J');
}
}
}