Willkommen bei den Lottozahlen,

nein das wird jetzt hier keine Glücksspielseite, sondern ich möchte euch hier ein kleines C Programm vorstellen.

Im rahmen meiner Umschulung zum Systemadministrator kommen auch wir nicht um die Programmiersprache C herum, von daher möchte ich euch ein kleines C-Programm vorstellen was das finden für die kommenden Lottozahlen etwas erleichtern dürfte. Man kann es auch als Gesellschaftsspiel sehen das ist ein Spaß für die ganze Familie.

#include<stdio.h>
#include<time.h>
#include<stdbool.h>
#include<iso646.h>



void lotto()
{
	int Lotto[49];
	int user[49] = { {0} };
	bool allmatch = true;
	bool nomatch = true;
	int matchcount = 0;

	srand(time(NULL));
	Lotto[0] = rand() % 49+1;
	Lotto[1] = rand() % 49+1;
	Lotto[2] = rand() % 49+1;
	Lotto[3] = rand() % 49+1;
	Lotto[4] = rand() % 49+1;
	Lotto[5] = rand() % 49+1;
	Lotto[6] = rand() % 49+1;

	/*for (int i = 0; i < 6; i++)
	{
		for (int h = 0; h < 6; h++)
		{
			if (Lotto[i] == Lotto[h] and i != h) {
				Lotto[i] = rand() % 49 + 1;
			}
		}
	}
	*/
	int neue_zahl;
	for (int i = 0; i < 6; i++)
	{
		bool zahl_ok = false;
		while (zahl_ok == false)
		{
			neue_zahl = rand() % 49 + 1;

			zahl_ok = true;
			for (int j = 0; j < 6; j++)
			{
				if (neue_zahl == Lotto[j])
				{
					zahl_ok = false;
					break;
				}
			}
			if (zahl_ok == true)
			{
				Lotto[i] = neue_zahl;
			}
		}
	}

	for (int i = 0; i < 6; i++)
	{
		{
			printf("Geben sie eine Zahl zwischen 1 und 49 ein : ");
		}
		scanf_s("%d", &user[i]);
		if (!(user[i] >=1 && user[i]<=49))

		{
			printf("Fehler! Es duerfen nur Zahlen zwischen 1 und 49 gewaelt werden\n ");
			scanf_s("%d", &user[i]);
			//return;
		}
	}
		// Auswertungsprozess
		
			printf("Gezogene Zahlen:\n ");
			for (int i = 0; i < 6; i++){

				printf("%d ", Lotto[i]);
				//printf("|");
		
		
				//printf("Angekreuzte Zahlen: %d\n ", user[i]);
			}
			printf("\nAngekreuzte Zahlen:\n");
			/*for (int i = 0; i < 6; i++) {

				//printf("%d", Lotto[i] / 2);
				//printf("|");


				printf("%d\n ", user[i]);
			}*/
		for (int i = 0; i < 6; i++)
		{
			printf("%d", user[i]);
			printf("|");
		}
		for (int i = 0; i < 6; i++)
		{
			if (user[i] == Lotto[i])
			{
				matchcount++;
				nomatch = false;
			}

			if (user[i] != Lotto[i])
			{
				allmatch = false;
			}
		}
		if (nomatch == true)
		{
			printf("\nLeider Verloren\n\n\n");
		}

		if (allmatch == true)
		{
			printf("Herzlichen Glueckwunsch sie haben 1.2 Mio. Euro Gewonnen\n");
		}
		if (matchcount != 0)
			printf("Richtige Zahlen: %d\n", matchcount);
		return 0;
		
	
}
void main() 
{
	char nochmal;
	do
	{
		lotto();
		printf("Noch ein Spiel?\n");
		fflush(stdout);
		scanf_s(" %c", &nochmal,1);
		//printf("%d\n", (int)nochmal);
	} while (nochmal == 'J');
	
}

Der Code darf frei verwendet und auch entsprechend angepasst werden.

Aber ich würde mich dennoch über ein positives Feedback freuen, schreibt mir doch einfach was ihr oder wo ihr den Code eingesetzt habt.

Ich wünsche euch nun viel Glück bei der Ziehung.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert