Last active
March 16, 2017 01:55
-
-
Save TomScotch/cbcbaa0edd22a40c3315a68e296d799f to your computer and use it in GitHub Desktop.
g++ lotto.cpp -o lotto && chmod +x lotto && ./lotto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> // input output c standard | |
| #include <string> // leichterer umgang mit namen als strings | |
| #include <cstdlib> // enthaelt random | |
| using namespace std; // leichter als immer std:: zu schreiben | |
| int pot = 100; | |
| int max_user = 100 ; // maximum user anzahl | |
| int max_tip = 45 ; // maximale tip groesse | |
| int anzahl ; // einzugebende anzahl der user | |
| string namen[100]; // feld zum speichern der namen der benutzer maximal 100 | |
| int tips[100][5]; // feld zum speichern der tips der user , sechs zahlen mit einer maximalen größe von 45 | |
| int zahlen[45]; // feld zum speichern der lottoziehung , max tip ist obergrenze | |
| //hello world | |
| int main () { | |
| //abfrage der gewinnsumme im pot | |
| cout << "bitte geben sie die groesse des pots ein (gewinnsumme)" << endl; | |
| cin >> pot ; cout << endl ; | |
| //MISCHEN DER ZAHLEN | |
| //die ersten sechs felder von zahlen ( 0 -5 ) | |
| //enthaelt am ende die lotto ziehung | |
| for (int i=0; i<45; i++){ | |
| zahlen[i]=i+1; | |
| } | |
| srand(time(NULL)); | |
| //mischen der zahlen im feld | |
| for (int i=0; i<45; i++) { | |
| int tausch = rand()%max_tip; | |
| int buffer = zahlen[i]; | |
| zahlen[i] = zahlen[tausch]; | |
| zahlen[tausch] = buffer; | |
| } | |
| // auskommentierte ausgabe der gezogenen lotto zahlen fuer test zwecke | |
| //cout << zahlen[0] << endl << zahlen[1] << endl << zahlen[2] << endl << zahlen[3] << endl << zahlen[4] << endl << zahlen[5] << endl ; | |
| //abfrage der anzahl der nutzer mit maximal 100 falls der wert groesser 100 | |
| cout << "bitte geben sie die anzahl der teilnehmer ein - maximal - " << max_user << endl; | |
| cin >> anzahl ; cout << endl ; | |
| if ( anzahl > max_user ) { | |
| anzahl = max_user ; | |
| } | |
| //ABFRAGE DER NUTZER EINGABEN | |
| //fuer alle nutzer ausführen | |
| for(int a = 0; a < anzahl; a++){ | |
| cout << endl; | |
| //eingabe wird im feld namen und index a gespeichert | |
| cout << "name" ; cout << endl; | |
| cin >> namen[a] ; cout << endl; | |
| //abfrage der getippten lottozahlen und speichern im feld tips mit index a und t | |
| cout << "bitte tippen sie ihre 6 zahlen ein , bestaetigen sie jeweils mit Enter *keine doppelten werte oder werte ueber 50*" ; cout << endl; | |
| for(int t = 0; t < 6; t++){ | |
| int tip = 0 ; | |
| cin>>tip; | |
| // *ACHTUNG* ist der tip groesser als max_tip wird 0 draus | |
| if (tip <= max_tip){ | |
| tips[a][t] = tip ; | |
| } | |
| } | |
| } | |
| //VERGLEICH UND AUSGABE | |
| //fuer alle nutzer ausführen | |
| for(int a = 0; a < anzahl; a++){ | |
| //zaehler fuer die uebereinstimmungen | |
| int treffer = 0; | |
| // zaehle wieviele treffer es gibt | |
| for(int c1 = 0 ; c1 < 6 ; c1++){ | |
| for(int c2 = 0; c2 < 6 ; c2++){ | |
| if (tips[a][c1] == zahlen[c2]) { | |
| treffer += 1 ; | |
| } | |
| } | |
| } | |
| //bei groesser zwei ausgabe | |
| if (treffer > 2) { | |
| //ausgabe des namens nach index a im feld namen und von int treffer sowie dem anteil am pott | |
| cout << endl << namen[a] << " hat " << treffer << " treffer und gewinnt " << pot / anzahl / 6 * treffer << endl ; | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment