What I want is that by default C is 0 but when the user adds 2 then it should display 2 and then when the user adds 4 it should be 6 but instead it displays 4 Any help would be appreciated!
public void addCash(View view) {
//Intent intent = new Intent(this, Main.class);
EditText val1 = (EditText) findViewById(R.id.num);
int b = 0;
int a = 0;
int c = 0;
int d = 0;
a = Integer.parseInt(val1.getText().toString());
if (c == 0) {
c = a + b;
}
else {
c = c + a;
}
TextView result = (TextView) findViewById(R.id.outPut);
result.setText(""+c);
//startActivity(intent);
}
cto0.cto be an instance variable in an object, not a local variable in a method. If it's a local variable in a method, you can't retain the value between method calls. The value goes away as soon asaddCashis done.c = a + bifbcan never be anything other than 0? You could just sayc = a. But since you only do this ifc == 0, sayingc = ais exactly the same asc = c + a. In other words, this wholeifstatement is redundant. Also, what isdthere for?