• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to add to a number.

ktUK

Newbie
I'm trying to make function where

int total = 0;

if (result == 6){

int total = one +1;

I know that I am making it incorrectly as you cannot have 2 different values for an int What is a different method I could use to do what I'm trying to achieve?

Thanks in advance
 
O dont understand your code at all. Are 'result' and 'one' variables (or constants) declared somewbere else? What exavtly are you trying to accomplish?
 
Sorry, part of the reason you don't understand it is that I altered some of it but forgot to alter the rest when I pasted it onto here. My fault sorry.
Here is the revised code with a bit extra


int total= 0;
int result= 1 + (int)(Math.random()*6);

if (result== 1){

int total= total +1;
}
show.setText(String.valueOf(total));
}


'Result' is the value of the equation

int result = 1 + (int)(Math.random()*6);

And 'Total' is supposed to be a running total that increases by 1 each time 'Result' equals 1. My aim is to have several equations and create a total of the number of times it equals 1(or any othe number). Creating this total is what I'm not sure on. I haven't declared it anywhere else in the code.

Thank you and my apologies for messing up the first post
 
>> int total = one +1;

Don't use the 'int' in this line.
If it's there you are creating a new variable within the 'if' block

total = total +1; can be simply written as total++; instead

 
Back
Top Bottom