3 Replies - 211 Views - Last Post: 08 February 2013 - 08:02 PM Rate Topic: -----

#1 ct1031  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-February 13

Problem with int and formula

Posted 08 February 2013 - 03:02 PM

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..

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with int and formula

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

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?

This post has been edited by GregBrannon: 08 February 2013 - 03:08 PM

Was This Post Helpful? 0
  • +
  • -

#3 flaminsnowman99  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 43
  • Joined: 15-December 12

Re: Problem with int and formula

Posted 08 February 2013 - 04:41 PM

One thing you could do is...
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.
Was This Post Helpful? 1
  • +
  • -

#4 natecat  Icon User is offline

  • D.I.C Head

Reputation: 53
  • View blog
  • Posts: 225
  • Joined: 19-December 11

Re: Problem with int and formula

Posted 08 February 2013 - 08:02 PM

View Postflaminsnowman99, on 08 February 2013 - 11:41 PM, said:

One thing you could do is...
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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1