How to store numbers in Arduino?

I have written this to an Arduino.

Click here to view, I couldn’t embed it

What I want to do is: - connect to serial (check) - collect 2 variables to add/subtract/multiply/divide later (check) - collect a variable to decide what to do with them 1-add, 2-subtract, etc. (check) - redirect the script to do the required operation (later) - print the result to serial (check)

The problem is, when I enter 1 and 1 and 1(whatever, the third one doesn’t count now) and I get 98 as a result. Any help? Maybe the variables are wrong?

I'll embed it for you

char incomingbytea;
char incomingbyteb;
char incomingop;
char result;

void setup()
{
	Serial.begin(9600);
}

void loop(){
	incomingbytea = 0;
	incomingbyteb = 0;
	incomingop = 0;
	result = 0;
	bytea:
  	if (Serial.available() > 0) {
    incomingbytea = Serial.read();
  	Serial.println("1ok");
  	Serial.println(incomingbytea);
  	goto byteb;
  	}
  	goto bytea;
  	byteb:
  	if (Serial.available() > 0) {
  	incomingbyteb = Serial.read();
  	Serial.println("2ok");
  	Serial.println(incomingbyteb);
  	goto op;
  	}
  	goto byteb;
  	op:
    if (Serial.available() > 0) {
  	incomingop = Serial.read();
    Serial.println("opok");
    Serial.println(incomingop);
    goto oper;
  	}
  	goto op;
  	oper:
  result = incomingbytea + incomingbyteb;
  Serial.println(result);
  Serial.println(incomingbytea);
  Serial.println(incomingbyteb);
  Serial.println(incomingop);
  
}

98 seems like an interesting number, but why?
Well let us take a look at this table, and I want you to try and figure it out.

I didn't know you can add type char variables together and expect an integer result.

varkokonyi:
Any help? Maybe the variables are wrong?

Maybe you don't know the difference between a 'number', 'character' and 'ASCII code'?

Look at this ASCII table:

The character '1' has the ASCII-code '49'.

So if you get 98 as the result when adding '1'+'1', you don't add the numbers, but you add the ASCII-codes of the characters '1' and '1', which is 49+49 and the result is 98.

You're using goto statements. They have been scorned as a source of trouble for about 40 years now. So how about fixing that too?

Ps991:
Well let us take a look at this table, and I want you to try and figure it out.

@jurs

aarg:
You're using goto statements. They have been scorned as a source of trouble for about 40 years now. So how about fixing that too?

OK, I want to get better. What should I use instead of them?

Ps991:
I'll embed it for you

char incomingbytea;

char incomingbyteb;
char incomingop;
char result;

void setup()
{
Serial.begin(9600);
}

void loop(){
incomingbytea = 0;
incomingbyteb = 0;
incomingop = 0;
result = 0;
bytea:
  if (Serial.available() > 0) {
    incomingbytea = Serial.read();
  Serial.println("1ok");
  Serial.println(incomingbytea);
  goto byteb;
  }
  goto bytea;
  byteb:
  if (Serial.available() > 0) {
  incomingbyteb = Serial.read();
  Serial.println("2ok");
  Serial.println(incomingbyteb);
  goto op;
  }
  goto byteb;
  op:
    if (Serial.available() > 0) {
  incomingop = Serial.read();
    Serial.println("opok");
    Serial.println(incomingop);
    goto oper;
  }
  goto op;
  oper:
  result = incomingbytea + incomingbyteb;
  Serial.println(result);
  Serial.println(incomingbytea);
  Serial.println(incomingbyteb);
  Serial.println(incomingop);
 
}




98 seems like an interesting number, but why?
Well let us take a look at this table, and I want you to try and figure it out.
![|500x341](http://www.asciitable.com/index/asciifull.gif)

Ok, I think I see what you mean. Thanks

OK, I want to get better. What should I use instead of them?

If you have:

label:
    // some code
    if(someCondition)
       goto label;

that is more conventionally done using:

   while(someCondition)
   {
      // some code
   }

Other (mis)uses of goto can be similarly replaced by thinking positively (do this if) instead of negatively (that didn't do what I wanted, so go back and try again).

While statements and return statements can eliminate 90+% of goto statements.

If you need help with a specific example, we're here to help.