0

I tried to come up with a Betting algorithm.

the problem lies after the "game mode selection". After you press 1 (second choice not coded) nothing happens.Only if you type 1 again and press Enter. Is there a way to fix it ? I tried a few things but nothing worked. hopefully someone can help me.

Thank you very much in advance !

#include<stdio.h>
#include<stdlib.h>
#include <time.h>

double Random_Number() {
    double ran_num;
    
    // Seed Generierung
    srand(time(NULL));
    
    ran_num = rand() / (double)RAND_MAX * 100.0;
    return ran_num;
}

double Single_Game(double Balance,double Bet,double Chance,double Multiplier){ //Function 

    Balance-=Bet;

    double Random= Random_Number();

    if (Random<=Chance)
    {
        Bet*=Multiplier;
        Balance+=Bet;
        printf("HERZLICHEN GLUECKWUNSCH!\nDu hast: %.2f Euro gewonnen !\nEs wurde %.2f gewuerfelt\nDein Neues Guthaben ist %.2f Euro", Bet,Random,Balance);
    }else printf("VERLOREN!\nEs wurde eine %.2f gewuerfelt.",Random);
}

/*double Multible_Games(double Balance,double Bet,double Chance_Selection){
        printf("Die Funktion ist noch nicht implementiert");
}*/

int main(){

int Game_Type,Choice;
double Balance,Bet;

printf("Wie dick ist der Geldbeutel? [Euro]\n");
scanf("%lf", &Balance);

printf("Wieviel willst du setzen ? [Euro]\n");                                                                                                                                                                                                                                                         //unter 47,5 für x2 // unter 63,33 für x1,5// unter 23 für x4//unert 10 x9,5 // unter 94 x1,01 //unter30 x3//unter 72 x1,3
scanf("%lf",&Bet);

while (Bet>Balance)//Prüfe ob die Wette kleiner ist als das Balance
{
    printf("Zu kleiner Geldbeutel. Bitte die Wette anpassen:\n");
    scanf("%lf",&Bet);
}



printf("Mit welcher Chance willst du spielen ?\n----------------------------------------------------------------------------\n|  Chance  |   10%%  |  23%%  |  30%%  |  47,5%%  |  63,3%%  |   72%%  |   94%%   |\n----------------------------------------------------------------------------\n|  Payout  |  x9,5  |  x4   |  x3   |   x2    |  x1,5   |  x1,3  |  x1,01  |\n----------------------------------------------------------------------------\n|  Waehle  |    1   |   2   |   3   |    4    |    5    |    6   |    7    |\n----------------------------------------------------------------------------\n");
scanf("%d",&Choice);

float Chances [] ={10.0, 23.0, 30.0, 47.5, 63.33, 72.0, 91.0};
float multipliers []= {9.5, 4.0, 3.0, 2.0, 1.5, 1.3, 1.01};

float Chance = Chances[Choice-1];
float Multiplier = multipliers[Choice-1];

if (Choice>=1 && Choice<=7)
{
    printf("Dein moeglicher Gewinn liegt bei %.2f Euro\n", Bet * Multiplier);
} else printf("Die Eingabe wurde nicht erkannt. Bitte neu starten.\n");


printf("Welcher Modus ?\n-------------------------------------\n|       Modus1       |    Modus2     |\n-------------------------------------\n|  Einmaliges Spiel  |  Automatisch  |\n-------------------------------------\n\n");
scanf("%d\n", &Game_Type);
while (Game_Type != 1 && Game_Type != 2)
{
    printf("Die Eingabe wurde nicht erkannt, bitte erneut eingeben:\n");
    scanf("%d", &Game_Type);
}
if (Game_Type==1)
{
    Single_Game(Balance, Bet, Chance, Multiplier);
} 

return 0;
}

I honestly dont really know if theres a easy fix.

Zerionic
  • 1
  • 3
  • thank you very much @Jabberwocky. I did it now the smart way. Thanks for checking by :) Do u have any idea how to solve the Terminal Softblock ? – Zerionic May 07 '23 at 13:06
  • Re: `scanf("%d\n", &Game_Type);` - Does this answer your question? [What is the effect of trailing white space in a scanf() format string?](https://stackoverflow.com/questions/19499060/what-is-the-effect-of-trailing-white-space-in-a-scanf-format-string) – Oka May 07 '23 at 13:23
  • Thanks for checking by @Oka. unfortuantly it didnt work. I reversed and updated my post again. – Zerionic May 07 '23 at 13:42
  • Read [`srand()` — why call it only once?](https://stackoverflow.com/questions/7343833/srand-why-call-it-only-once/) and repent of thy non-random ways. – Jonathan Leffler May 07 '23 at 15:20

0 Answers0