Hi @CryptoDiddy,
First of all — nice contract
If you don’t need to store the total price (litres x price per litre) in the mapping, and you just want to return it to the caller of showDeal(), then you just need to…
You can temporarily store the result of the multiplication calculation in a local variable…
// you can give this local variable whatever identifier (name) you want
uint totalPrice =
currentDeal[creator].Litres * currentDeal[creator].PricePerLitre;
As you already have a return statement, you just need to add a reference to the local variable in the return statement:
return(
currentDeal[creator].CompanyName,
currentDeal[creator].Litres,
currentDeal[creator].PricePerLitre,
totalPrice // references the value stored in the local variable
);
and then declare this additional return value in returns()
in the function header:
returns(
string memory CompanyName,
uint Litres,
uint PricePerLitre,
uint total // you can give this whatever identifier (name) you want
)
So, if you want to store the total price (litres x price per litre) in each Deal instance when it’s created, you need an extra property in the Deal struct e.g. uint totalPrice;
and then, instead of assigning the result of the multiplication calculation to a local variable in the showDeal function, assign it to this additional property in each new Deal Instance created in the createDeal function:
newDeal.totalPrice = Litres * PricePerLitre;
If you do it this way, then you don’t need to perform the multiplication calculation in the showDeal function; you just need to reference the result that is already stored in the Deal instance’s extra property in the mapping:
return(
currentDeal[creator].CompanyName,
currentDeal[creator].Litres,
currentDeal[creator].PricePerLitre,
currentDeal[creator].totalPrice // references value stored in mapping
);