/****************************************************
Programm:       Wuerfel
Dateien:        wurfel.cpp
Funktionen:     main(): Aufzaehlen und Ausgabe
                balken(): Zeichnen eines Balkens
Beschreibung:   Simulation eines Wuerfels
Author:         Michael Hoeppenstein
Version:        1.00        08.10.2017        (mh)
*****************************************************/

#include <iostream>
#include <cstdlib> // Für Zufallszahlen
#include <ctime>   // nötig

using namespace std;

int balken(unsigned long x); // Prototyp

main()
{
        unsigned short wurf;
        unsigned long summe=0, anzahl=1000;
        unsigned long eins=0, zwei=0, drei=0, vier=0, funf=0, sechs=0;
        srand (time(NULL)); // Initialisierung des Zufallsgenerators
        cout << "+++++++++++++++++++++++++++++++\n";
        cout << "+  Simulation eines Wuerfels  +\n";
        cout << "+++++++++++++++++++++++++++++++\n\n";
        cout << "Anzahl der Wuerfe: "<< anzahl << "\n\n";
        for (int i=0; i<anzahl; i++)
        {
                // Zufallszahlen zwischen 1 und 6 werden generiert
                wurf = rand() % 6 + 1;
                if (wurf == 1)
                        eins++;
                if (wurf == 2)
                        zwei++;
                if (wurf == 3)
                        drei++;
                if (wurf == 4)
                        vier++;
                if (wurf == 5)
                        funf++;
                if (wurf == 6)
                        sechs++;
                summe = summe+wurf;
        }
        cout << "1: ";
        balken(eins);
        cout << "2: ";
        balken(zwei);
        cout << "3: ";
        balken(drei);
        cout << "4: ";
        balken(vier);
        cout << "5: ";
        balken(funf);
        cout << "6: ";
        balken(sechs);
        cout << "\nArithmetisches Mittel: " << (float)summe/(float)anzahl;
}

int balken(unsigned long x)
{
        for (int i=0; i<x; i++)
        {
                if (i%5 == 0) // wenn i durch 5 teilbar ist
                {
                        for (unsigned long j=0; j<10000000; j++)
                                ; // Verzögerungsschleife
                        cout << "=";
                }
        }
        cout << "  " << x << endl;
        return 0;
}
