# How to take input from the user only once with the help of a function and then use it in all of the other functions?

Here I take input from the user in every function to perform the calculation but what if I wanted to take the two input numbers from the user only once and then perform all the rest of functions with those 2 numbers only. Like take the input numbers and then only click the specific button for the function that comes after deploying the contract in remix. For addition, subtraction etc.

Code:

``````//SPDX-License-Identifier:MIT;
pragma solidity >=0.8.0 < 0.9.0;

contract SimpleCalculator{
function addTwoNumbers(uint256 number1,uint256 number2) public view returns(uint256){
uint256 addition = number1 + number2;
}
function subtractTwoNumbers(int number1,int256 number2) public view returns(int256){
int256 subtraction = number1 - number2;
return subtraction;
}
function divideTwoNumbers(uint256 number1,uint number2) public view returns(uint256){
uint256 division = number1/number2;
return division;
}
function multiplyTwoNumbers(uint256 number1, uint256 number2) public view returns(uint256){
uint256 multiplication = number1*number2;
return multiplication;
}
}
``````

I'm not really sure what you need, but I wrote this quick example of how to have a single function that orchestrates all the operations and returns one result with all the operations.

Take a look at the `doAllOperations` function. Basically I created an `Operations` struct to save all the results of all these operations and return this struct:

``````//SPDX-License-Identifier:MIT;
pragma solidity >=0.8.0 < 0.9.0;

struct Operations {
uint256 sum;
uint256 substraction;
uint256 division;
uint256 multiplication;
}

contract SimpleCalculator {

function doAllOperations(uint256 number1,uint256 number2) public pure returns(Operations memory) {

Operations memory operationsResult = Operations({
substraction: subtractTwoNumbers(number1, number2),
division: divideTwoNumbers(number1, number2),
multiplication: multiplyTwoNumbers(number1, number2)
});

return operationsResult;

}

function addTwoNumbers(uint256 number1, uint256 number2) public pure returns(uint256) {
uint256 addition = number1 + number2;
}

function subtractTwoNumbers(uint256 number1, uint256 number2) public pure returns(uint256) {
uint256 subtraction = number1 - number2;
return subtraction;
}

function divideTwoNumbers(uint256 number1, uint number2) public pure returns(uint256) {
uint256 division = number1/number2;
return division;
}

function multiplyTwoNumbers(uint256 number1, uint256 number2) public pure returns(uint256) {
uint256 multiplication = number1*number2;
return multiplication;
}

}
``````

Here I got you covered:

``````//SPDX-License-Identifier:MIT;
pragma solidity >=0.8.0 < 0.9.0;

contract SimpleCalculator{

uint number1;
uint number2;

function setImputNumbers(uint firstNumber, uint secondNumber) public {
number1 = firstNumber;
number2 = secondNumber;
}

uint256 addition = number1 + number2;
}

function subtractTwoNumbers() public view returns(int256){
int256 subtraction = int(number1) - int(number2);
return subtraction;
}

function divideTwoNumbers() public view returns(uint256){
uint256 division = number1/number2;
return division;
}

function multiplyTwoNumbers() public view returns(uint256){
uint256 multiplication = number1*number2 ;
return multiplication;
}

}
``````

It's a simple code that does exactly what you requested. So now you can play/experiment with it. I haven't optimized or covered possible mathematical edge cases that can go wrong (division by zero). But its perfectly suitable otherwise for learning solidity.