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.
java
add a comment |
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.
java
I'm afraid while it's clear why there's an infinite loop, it's not clear what you want to do. You've saidvalorcartabancamin
goes from 1 to 11, but it doesn't, it's always 1. Do you mean to increment it? Or to repeatedly add tovalorcartabanca
, or...?
– T.J. Crowder
Nov 7 at 9:11
add a comment |
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.
java
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
java
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 saidvalorcartabancamin
goes from 1 to 11, but it doesn't, it's always 1. Do you mean to increment it? Or to repeatedly add tovalorcartabanca
, or...?
– T.J. Crowder
Nov 7 at 9:11
add a comment |
I'm afraid while it's clear why there's an infinite loop, it's not clear what you want to do. You've saidvalorcartabancamin
goes from 1 to 11, but it doesn't, it's always 1. Do you mean to increment it? Or to repeatedly add tovalorcartabanca
, 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
add a comment |
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 =
.
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
add a comment |
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);
}
You can't use+=
when you haven't initializedvalorcartabanca
.
– 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
add a comment |
up vote
-1
down vote
you are not accumulating valorcartablanca.
try
int valorcartabanca = 1;
do {
valorcartabanca = valorcartabancamin + (byte) (Math.random() * 10);
}while (valorcartabanca<15);
add a comment |
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 =
.
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
add a comment |
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 =
.
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
add a comment |
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 =
.
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 =
.
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
add a comment |
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
add a comment |
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);
}
You can't use+=
when you haven't initializedvalorcartabanca
.
– 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
add a comment |
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);
}
You can't use+=
when you haven't initializedvalorcartabanca
.
– 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
add a comment |
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);
}
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);
}
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 initializedvalorcartabanca
.
– 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
add a comment |
You can't use+=
when you haven't initializedvalorcartabanca
.
– 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
add a comment |
up vote
-1
down vote
you are not accumulating valorcartablanca.
try
int valorcartabanca = 1;
do {
valorcartabanca = valorcartabancamin + (byte) (Math.random() * 10);
}while (valorcartabanca<15);
add a comment |
up vote
-1
down vote
you are not accumulating valorcartablanca.
try
int valorcartabanca = 1;
do {
valorcartabanca = valorcartabancamin + (byte) (Math.random() * 10);
}while (valorcartabanca<15);
add a comment |
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);
you are not accumulating valorcartablanca.
try
int valorcartabanca = 1;
do {
valorcartabanca = valorcartabancamin + (byte) (Math.random() * 10);
}while (valorcartabanca<15);
answered Nov 7 at 9:08
EduSanCon
38117
38117
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 tovalorcartabanca
, or...?– T.J. Crowder
Nov 7 at 9:11