Trouble in making a while bucle in a blackjack game











up vote
0
down vote

favorite












private static void generarbanca() {
int valorcartabanca;
do {
int valorcartabancamin = 1;// from one to 11
valorcartabanca = valorcartabancamin + (byte) (Math.random() * 10);
}while (valorcartabanca<15);
}


valorcartamin is the minimun number that I want to generate for the crupier, so the problem is that program get in a infite loop.
I want it to generate number until 15 point score is reached and count the number needed till 15 and so on.










share|improve this question
























  • I'm afraid while it's clear why there's an infinite loop, it's not clear what you want to do. You've said valorcartabancamin goes from 1 to 11, but it doesn't, it's always 1. Do you mean to increment it? Or to repeatedly add to valorcartabanca, or...?
    – T.J. Crowder
    Nov 7 at 9:11















up vote
0
down vote

favorite












private static void generarbanca() {
int valorcartabanca;
do {
int valorcartabancamin = 1;// from one to 11
valorcartabanca = valorcartabancamin + (byte) (Math.random() * 10);
}while (valorcartabanca<15);
}


valorcartamin is the minimun number that I want to generate for the crupier, so the problem is that program get in a infite loop.
I want it to generate number until 15 point score is reached and count the number needed till 15 and so on.










share|improve this question
























  • I'm afraid while it's clear why there's an infinite loop, it's not clear what you want to do. You've said valorcartabancamin goes from 1 to 11, but it doesn't, it's always 1. Do you mean to increment it? Or to repeatedly add to valorcartabanca, or...?
    – T.J. Crowder
    Nov 7 at 9:11













up vote
0
down vote

favorite









up vote
0
down vote

favorite











private static void generarbanca() {
int valorcartabanca;
do {
int valorcartabancamin = 1;// from one to 11
valorcartabanca = valorcartabancamin + (byte) (Math.random() * 10);
}while (valorcartabanca<15);
}


valorcartamin is the minimun number that I want to generate for the crupier, so the problem is that program get in a infite loop.
I want it to generate number until 15 point score is reached and count the number needed till 15 and so on.










share|improve this question















private static void generarbanca() {
int valorcartabanca;
do {
int valorcartabancamin = 1;// from one to 11
valorcartabanca = valorcartabancamin + (byte) (Math.random() * 10);
}while (valorcartabanca<15);
}


valorcartamin is the minimun number that I want to generate for the crupier, so the problem is that program get in a infite loop.
I want it to generate number until 15 point score is reached and count the number needed till 15 and so on.







java






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 9:11









T.J. Crowder

667k11611771273




667k11611771273










asked Nov 7 at 9:06









IagoPM

12




12












  • I'm afraid while it's clear why there's an infinite loop, it's not clear what you want to do. You've said valorcartabancamin goes from 1 to 11, but it doesn't, it's always 1. Do you mean to increment it? Or to repeatedly add to valorcartabanca, or...?
    – T.J. Crowder
    Nov 7 at 9:11


















  • I'm afraid while it's clear why there's an infinite loop, it's not clear what you want to do. You've said valorcartabancamin goes from 1 to 11, but it doesn't, it's always 1. Do you mean to increment it? Or to repeatedly add to valorcartabanca, or...?
    – T.J. Crowder
    Nov 7 at 9:11
















I'm afraid while it's clear why there's an infinite loop, it's not clear what you want to do. You've said valorcartabancamin goes from 1 to 11, but it doesn't, it's always 1. Do you mean to increment it? Or to repeatedly add to valorcartabanca, or...?
– T.J. Crowder
Nov 7 at 9:11




I'm afraid while it's clear why there's an infinite loop, it's not clear what you want to do. You've said valorcartabancamin goes from 1 to 11, but it doesn't, it's always 1. Do you mean to increment it? Or to repeatedly add to valorcartabanca, or...?
– T.J. Crowder
Nov 7 at 9:11












3 Answers
3






active

oldest

votes

















up vote
1
down vote













1 + (Math.random() * 10) will always be less than 15. Did you want to write



valorcartabanca += valorcartabancamin + (byte) (Math.random() * 10);


Note the += instead of a simple =.






share|improve this answer





















  • no, I want the program to generate values from 1-11 until it's 15 or more
    – IagoPM
    Nov 7 at 9:30










  • @IagoPalleiro well, numbers from 1-11 will never be 15 or more.
    – luk2302
    Nov 7 at 9:31




















up vote
0
down vote













You need to extract the initialization of valorcartabancamin from the loop, and in addition you need to keep the current value of valorcartabanca, so use the += operator:



 private static void generarbanca() {
int valorcartabancamin = 1;// desde uno hasta 11
int valorcartabanca = 0;
do {
valorcartabanca += valorcartabancamin + (byte) (Math.random() * 10);
} while (valorcartabanca<15);
}





share|improve this answer























  • You can't use += when you haven't initialized valorcartabanca.
    – T.J. Crowder
    Nov 7 at 9:12










  • Thanks a lot m8
    – IagoPM
    Nov 7 at 9:38










  • On Stackoverflow you could give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.
    – Bsquare
    Nov 7 at 9:43


















up vote
-1
down vote













you are not accumulating valorcartablanca.
try



int valorcartabanca = 1;
do {
valorcartabanca = valorcartabancamin + (byte) (Math.random() * 10);
}while (valorcartabanca<15);





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186325%2ftrouble-in-making-a-while-bucle-in-a-blackjack-game%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    1 + (Math.random() * 10) will always be less than 15. Did you want to write



    valorcartabanca += valorcartabancamin + (byte) (Math.random() * 10);


    Note the += instead of a simple =.






    share|improve this answer





















    • no, I want the program to generate values from 1-11 until it's 15 or more
      – IagoPM
      Nov 7 at 9:30










    • @IagoPalleiro well, numbers from 1-11 will never be 15 or more.
      – luk2302
      Nov 7 at 9:31

















    up vote
    1
    down vote













    1 + (Math.random() * 10) will always be less than 15. Did you want to write



    valorcartabanca += valorcartabancamin + (byte) (Math.random() * 10);


    Note the += instead of a simple =.






    share|improve this answer





















    • no, I want the program to generate values from 1-11 until it's 15 or more
      – IagoPM
      Nov 7 at 9:30










    • @IagoPalleiro well, numbers from 1-11 will never be 15 or more.
      – luk2302
      Nov 7 at 9:31















    up vote
    1
    down vote










    up vote
    1
    down vote









    1 + (Math.random() * 10) will always be less than 15. Did you want to write



    valorcartabanca += valorcartabancamin + (byte) (Math.random() * 10);


    Note the += instead of a simple =.






    share|improve this answer












    1 + (Math.random() * 10) will always be less than 15. Did you want to write



    valorcartabanca += valorcartabancamin + (byte) (Math.random() * 10);


    Note the += instead of a simple =.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 7 at 9:09









    luk2302

    32k166588




    32k166588












    • no, I want the program to generate values from 1-11 until it's 15 or more
      – IagoPM
      Nov 7 at 9:30










    • @IagoPalleiro well, numbers from 1-11 will never be 15 or more.
      – luk2302
      Nov 7 at 9:31




















    • no, I want the program to generate values from 1-11 until it's 15 or more
      – IagoPM
      Nov 7 at 9:30










    • @IagoPalleiro well, numbers from 1-11 will never be 15 or more.
      – luk2302
      Nov 7 at 9:31


















    no, I want the program to generate values from 1-11 until it's 15 or more
    – IagoPM
    Nov 7 at 9:30




    no, I want the program to generate values from 1-11 until it's 15 or more
    – IagoPM
    Nov 7 at 9:30












    @IagoPalleiro well, numbers from 1-11 will never be 15 or more.
    – luk2302
    Nov 7 at 9:31






    @IagoPalleiro well, numbers from 1-11 will never be 15 or more.
    – luk2302
    Nov 7 at 9:31














    up vote
    0
    down vote













    You need to extract the initialization of valorcartabancamin from the loop, and in addition you need to keep the current value of valorcartabanca, so use the += operator:



     private static void generarbanca() {
    int valorcartabancamin = 1;// desde uno hasta 11
    int valorcartabanca = 0;
    do {
    valorcartabanca += valorcartabancamin + (byte) (Math.random() * 10);
    } while (valorcartabanca<15);
    }





    share|improve this answer























    • You can't use += when you haven't initialized valorcartabanca.
      – T.J. Crowder
      Nov 7 at 9:12










    • Thanks a lot m8
      – IagoPM
      Nov 7 at 9:38










    • On Stackoverflow you could give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.
      – Bsquare
      Nov 7 at 9:43















    up vote
    0
    down vote













    You need to extract the initialization of valorcartabancamin from the loop, and in addition you need to keep the current value of valorcartabanca, so use the += operator:



     private static void generarbanca() {
    int valorcartabancamin = 1;// desde uno hasta 11
    int valorcartabanca = 0;
    do {
    valorcartabanca += valorcartabancamin + (byte) (Math.random() * 10);
    } while (valorcartabanca<15);
    }





    share|improve this answer























    • You can't use += when you haven't initialized valorcartabanca.
      – T.J. Crowder
      Nov 7 at 9:12










    • Thanks a lot m8
      – IagoPM
      Nov 7 at 9:38










    • On Stackoverflow you could give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.
      – Bsquare
      Nov 7 at 9:43













    up vote
    0
    down vote










    up vote
    0
    down vote









    You need to extract the initialization of valorcartabancamin from the loop, and in addition you need to keep the current value of valorcartabanca, so use the += operator:



     private static void generarbanca() {
    int valorcartabancamin = 1;// desde uno hasta 11
    int valorcartabanca = 0;
    do {
    valorcartabanca += valorcartabancamin + (byte) (Math.random() * 10);
    } while (valorcartabanca<15);
    }





    share|improve this answer














    You need to extract the initialization of valorcartabancamin from the loop, and in addition you need to keep the current value of valorcartabanca, so use the += operator:



     private static void generarbanca() {
    int valorcartabancamin = 1;// desde uno hasta 11
    int valorcartabanca = 0;
    do {
    valorcartabanca += valorcartabancamin + (byte) (Math.random() * 10);
    } while (valorcartabanca<15);
    }






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 7 at 9:16

























    answered Nov 7 at 9:09









    Bsquare

    1,183225




    1,183225












    • You can't use += when you haven't initialized valorcartabanca.
      – T.J. Crowder
      Nov 7 at 9:12










    • Thanks a lot m8
      – IagoPM
      Nov 7 at 9:38










    • On Stackoverflow you could give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.
      – Bsquare
      Nov 7 at 9:43


















    • You can't use += when you haven't initialized valorcartabanca.
      – T.J. Crowder
      Nov 7 at 9:12










    • Thanks a lot m8
      – IagoPM
      Nov 7 at 9:38










    • On Stackoverflow you could give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.
      – Bsquare
      Nov 7 at 9:43
















    You can't use += when you haven't initialized valorcartabanca.
    – T.J. Crowder
    Nov 7 at 9:12




    You can't use += when you haven't initialized valorcartabanca.
    – T.J. Crowder
    Nov 7 at 9:12












    Thanks a lot m8
    – IagoPM
    Nov 7 at 9:38




    Thanks a lot m8
    – IagoPM
    Nov 7 at 9:38












    On Stackoverflow you could give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.
    – Bsquare
    Nov 7 at 9:43




    On Stackoverflow you could give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.
    – Bsquare
    Nov 7 at 9:43










    up vote
    -1
    down vote













    you are not accumulating valorcartablanca.
    try



    int valorcartabanca = 1;
    do {
    valorcartabanca = valorcartabancamin + (byte) (Math.random() * 10);
    }while (valorcartabanca<15);





    share|improve this answer

























      up vote
      -1
      down vote













      you are not accumulating valorcartablanca.
      try



      int valorcartabanca = 1;
      do {
      valorcartabanca = valorcartabancamin + (byte) (Math.random() * 10);
      }while (valorcartabanca<15);





      share|improve this answer























        up vote
        -1
        down vote










        up vote
        -1
        down vote









        you are not accumulating valorcartablanca.
        try



        int valorcartabanca = 1;
        do {
        valorcartabanca = valorcartabancamin + (byte) (Math.random() * 10);
        }while (valorcartabanca<15);





        share|improve this answer












        you are not accumulating valorcartablanca.
        try



        int valorcartabanca = 1;
        do {
        valorcartabanca = valorcartabancamin + (byte) (Math.random() * 10);
        }while (valorcartabanca<15);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 7 at 9:08









        EduSanCon

        38117




        38117






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186325%2ftrouble-in-making-a-while-bucle-in-a-blackjack-game%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini