# How to add two integer values using addition function in solidity using smart contracts?

``````pragma solidity ^0.4.18;

uint a;
uint b;
uint c;

{
creator = msg.sender;                                // msg is a global variable
uint c = uint a + uint b; //here i am getting an error that expected token semicolon got identifier
}

{
return uint c;
}

/**********
Standard kill() function to recover funds
**********/

function kill()
{
if (msg.sender == creator)
suicide(creator);  // kills this contract and sends remaining funds back to creator
}

}
``````

It's better to use the SafeMath library functions, this is the addition fucntion:

``````function add(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
``````

``````c =a.add(b);
``````

Note: If you don't want to use SafeMath (which you should), here is corrected syntax for your original code:

``````address creator;
uint a;
uint b;
uint c;

{
creator = msg.sender;                                // msg is a global variable
uint c = a + b; //here i am getting an error that expected token semicolon got identifier
}
``````

The difference is that you don't put the type of a variable when referring to it, only when declaring it.

You only need to declare `uint c` the first time — after that you just refer to it as `c`.

```function addition() public { creator = msg.sender; c = a + b; }```

There were a few other errors in your code, which I fixed in the following fiddle:

https://ethfiddle.com/O1z7aGXF3Y

You can play around with it there and see that it adds the integers as expected.

• Thanx but i have run your updated code in remix it is not returning 3. ? – Deepak Baberwal Nov 16 '17 at 8:25
• You have to run the `addition` function first, which adds the two integers. Then check the `getResult` function – James Duffy Nov 16 '17 at 15:00
• @DeepakBaberwal You cannot return a value from a transaction see this ethereum.stackexchange.com/questions/765/… – Ismael Nov 16 '17 at 21:31

This code is working for me :

``````pragma solidity ^0.4.0;