hello
I am new to coding....
I am creating a app to play craps..roll the dice
I am having trouble generating the integer range and when I get to the formula it states "the bad operand types for binary operator '+''
int [] dice1={1,2,3,4,5,6};
int[] dice2={1,2,3,4,5,6};
int Roll1(){
int Value=(dice1)+(dice2); //this is where the error is
return Value;
}
it suppose to be random rolls with the options between 1 and 6
I know that I have to use the new java.util.Random() I have not done that yet..
Problem with int and formula
Page 1 of 13 Replies - 115 Views - Last Post: 08 February 2013 - 08:02 PM
Replies To: Problem with int and formula
#2
Re: Problem with int and formula
Posted 08 February 2013 - 03:07 PM
dice1[] and dice2[] are integer arrays. To reference the arrays (pass to methods, etc.) you use the array name by itself, like "dice1" and "dice2". dice1 and dice2 can't meaningfully be added together as you're showing:
int Value=(dice1)+(dice2);
at least not as an integer value, but I'm not sure why you'd want to do that as any type.
What are you trying to do with that statement?
int Value=(dice1)+(dice2);
at least not as an integer value, but I'm not sure why you'd want to do that as any type.
What are you trying to do with that statement?
This post has been edited by GregBrannon: 08 February 2013 - 03:08 PM
#3
Re: Problem with int and formula
Posted 08 February 2013 - 04:41 PM
One thing you could do is...
This saves you the trouble of using arrays and in my opinion makes the programs simpler.
Random rad = new Random(); int dice1, dice2, diceTotal; dice1 = rad.nextInt(6); dice2 = rad.nextInt(6); diceTotal = dice1 + dice2;
This saves you the trouble of using arrays and in my opinion makes the programs simpler.
#4
Re: Problem with int and formula
Posted 08 February 2013 - 08:02 PM
flaminsnowman99, on 08 February 2013 - 11:41 PM, said:
One thing you could do is...
This saves you the trouble of using arrays and in my opinion makes the programs simpler.
Random rad = new Random(); int dice1, dice2, diceTotal; dice1 = rad.nextInt(6); dice2 = rad.nextInt(6); diceTotal = dice1 + dice2;
This saves you the trouble of using arrays and in my opinion makes the programs simpler.
Add 2 to the diceTotal, his arrays start at 1, not 0
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|