Advertisement
Guest User

Untitled

a guest
May 28th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. /**********************************************************************************************
  2. ** Programmersteller: ILLICH 2BHEL (4) **
  3. ** Programmtitel: Glücksspiel **
  4. ** Datum-Arbeitsbeginn: 28.5.2018 **
  5. ** Datum-Letzte Änderung: 28.5.2018 **
  6. ** Anmerkungen: --- **
  7. ***********************************************************************************************/
  8. #include <iostream> // für cin, cout, ...
  9. #include <conio.h> // für _getch, ...
  10. #include <ctime> // für time() ,..
  11. #define _USE_MATH_DEFINES // damit die Definition von M_PI, M_Pi_2, etc. in math.h aktiv wird
  12. #include <math.h>
  13. #include <cstdlib>
  14. using namespace std;
  15.  
  16.  
  17.  
  18.  
  19. void getRandom(int randomfeld[4]){ //Die Zufallszahlengenerierung
  20. int anzahl;
  21. do{
  22. cout<<"Wieviele Zahlen sollen ermittelt werden? (1..30)";
  23. cin>>anzahl;
  24. cout<<" \n";
  25. }while(anzahl >= 30 || anzahl <= 0);
  26. for (int i=0; i<anzahl; i++)
  27. randomfeld[i]=rand()%3+1;
  28. for (int i=0; i<anzahl; i++)
  29. cout<<randomfeld[i]<<" ";
  30.  
  31.  
  32. }
  33. // Prototypen d. Unterprogramme:
  34. void meinezahl(int a){ //Einlesen von der Gewünschten Zahl
  35. int meinezahl;
  36. do{
  37. cout<<"Ihre Glückszahlen (1..3): ";
  38. cin>>meinezahl;
  39. system ("CLS");
  40. cout<<"Ihre Glückszahlen (1..3): ";
  41. cout<<meinezahl<<endl;
  42. }while(meinezahl >= 4 || meinezahl <= 0);
  43. }
  44.  
  45. int rückgabeVergleich(int &randomfeld[4], int &meinezahl, int &anzahl){ //Die Rückgabe von dem Vergleich (Ohne dieser Funktion ist das Programm lauffähig...)
  46. int c, geld;
  47. double prozente;
  48. c=0;
  49. geld=50;
  50. for (int i=0; i<anzahl; i++)
  51. if (meinezahl==randomfeld[i])
  52. c++;
  53. prozente=(c/anzahl)*100;
  54. cout<<"Ihre Zahl wurde "<< c <<" mal gezogen, das entspricht "<<prozente<<" %\n";
  55. if(prozente >= 40){
  56. cout<<"Das liegt über 40 %. Sie haben gewonnen!\n";
  57. geld+2;
  58.  
  59. }
  60. if (prozente < 40){
  61. cout<<"Das liegt unter 40 %. Sie haben verloren!\n";
  62. geld+0;
  63. }
  64.  
  65.  
  66. return NULL;
  67.  
  68.  
  69. }
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. bool nochmals();
  77. void Preliminarien();
  78.  
  79. int main() {
  80. // *** Variablendeklarationen:
  81. int randomfeld[4], a, anzahl;
  82.  
  83. // Allgemeine Initialisierungen
  84. Preliminarien();
  85.  
  86. //Hauptprogramms-Schleife:
  87. do {
  88. system ("CLS"); // Löscht den Bildschirm (betriebssystemanhängig)
  89. cout<<"* * * G l u e c k s s p i e l * * * \n";
  90. meinezahl(a); // *** Hier kommt nun das eigentliche Hauptprogramm hin:
  91. getRandom(randomfeld);
  92. rückgabeVergleich(&randomfeld, &meinezahl, &anzahl);
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. } while (nochmals());
  101.  
  102. } //main
  103.  
  104. bool nochmals() {
  105. cout << "\n\nWollen Sie diese Programm nochmals ablaufen lassen? (J/n)-> ";
  106. return toupper(_getch()) != 'N';
  107. } //nochmals
  108.  
  109. // Allgemeine Initialisierungen
  110. void Preliminarien() {
  111. setlocale (LC_ALL, "German"); //ermöglicht es, Umlaute udgl in den Ausgaben zu verwenden
  112. srand (unsigned(time(0))); // Initialisierung des Zufallszahlengenerators mit der
  113. } //Preliminarien // "zufälligen" Sekunde der Systemzeit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement