Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**********************************************************************************************
- ** Programmersteller: ILLICH 2BHEL (4) **
- ** Programmtitel: Glücksspiel **
- ** Datum-Arbeitsbeginn: 28.5.2018 **
- ** Datum-Letzte Änderung: 28.5.2018 **
- ** Anmerkungen: --- **
- ***********************************************************************************************/
- #include <iostream> // für cin, cout, ...
- #include <conio.h> // für _getch, ...
- #include <ctime> // für time() ,..
- #define _USE_MATH_DEFINES // damit die Definition von M_PI, M_Pi_2, etc. in math.h aktiv wird
- #include <math.h>
- #include <cstdlib>
- using namespace std;
- void getRandom(int randomfeld[4]){ //Die Zufallszahlengenerierung
- int anzahl;
- do{
- cout<<"Wieviele Zahlen sollen ermittelt werden? (1..30)";
- cin>>anzahl;
- cout<<" \n";
- }while(anzahl >= 30 || anzahl <= 0);
- for (int i=0; i<anzahl; i++)
- randomfeld[i]=rand()%3+1;
- for (int i=0; i<anzahl; i++)
- cout<<randomfeld[i]<<" ";
- }
- // Prototypen d. Unterprogramme:
- void meinezahl(int a){ //Einlesen von der Gewünschten Zahl
- int meinezahl;
- do{
- cout<<"Ihre Glückszahlen (1..3): ";
- cin>>meinezahl;
- system ("CLS");
- cout<<"Ihre Glückszahlen (1..3): ";
- cout<<meinezahl<<endl;
- }while(meinezahl >= 4 || meinezahl <= 0);
- }
- int rückgabeVergleich(int &randomfeld[4], int &meinezahl, int &anzahl){ //Die Rückgabe von dem Vergleich (Ohne dieser Funktion ist das Programm lauffähig...)
- int c, geld;
- double prozente;
- c=0;
- geld=50;
- for (int i=0; i<anzahl; i++)
- if (meinezahl==randomfeld[i])
- c++;
- prozente=(c/anzahl)*100;
- cout<<"Ihre Zahl wurde "<< c <<" mal gezogen, das entspricht "<<prozente<<" %\n";
- if(prozente >= 40){
- cout<<"Das liegt über 40 %. Sie haben gewonnen!\n";
- geld+2;
- }
- if (prozente < 40){
- cout<<"Das liegt unter 40 %. Sie haben verloren!\n";
- geld+0;
- }
- return NULL;
- }
- bool nochmals();
- void Preliminarien();
- int main() {
- // *** Variablendeklarationen:
- int randomfeld[4], a, anzahl;
- // Allgemeine Initialisierungen
- Preliminarien();
- //Hauptprogramms-Schleife:
- do {
- system ("CLS"); // Löscht den Bildschirm (betriebssystemanhängig)
- cout<<"* * * G l u e c k s s p i e l * * * \n";
- meinezahl(a); // *** Hier kommt nun das eigentliche Hauptprogramm hin:
- getRandom(randomfeld);
- rückgabeVergleich(&randomfeld, &meinezahl, &anzahl);
- } while (nochmals());
- } //main
- bool nochmals() {
- cout << "\n\nWollen Sie diese Programm nochmals ablaufen lassen? (J/n)-> ";
- return toupper(_getch()) != 'N';
- } //nochmals
- // Allgemeine Initialisierungen
- void Preliminarien() {
- setlocale (LC_ALL, "German"); //ermöglicht es, Umlaute udgl in den Ausgaben zu verwenden
- srand (unsigned(time(0))); // Initialisierung des Zufallszahlengenerators mit der
- } //Preliminarien // "zufälligen" Sekunde der Systemzeit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement