Reputation: 33
Hello I am trying to create a program that has a function main_function()
that holds two int variables and then passes the variables to two other functions difference()
and sum()
. I want the two functions perform the computation and display the results. In turn calling each of the two functions from the main_function()
. However I am currently having an issue with my program only outputting the bottom most function that is being called in the main_function()
Here is what I have
-module(numbers).
-export([main_function/2]).
main_function(X,Y)->
sum(X,Y),
difference(X,Y).
sum(X,Y)->
X + Y.
difference(X,Y)->
X - Y.
My output for this would be 2 if I was to pass 5 and 3 would for X and Y respectively and my program seems to be only using the difference()
function and not sum()
. I am looking for an output of 8 and 2.
Any help is greatly appreciated
Thanks
Upvotes: 1
Views: 72
Reputation: 1369
You can change main_function/2 like below
main_function(X,Y)->
A = sum(X,Y),
B = difference(X,Y),
{A, B}.
The result in shell when X = 5, Y = 3 is:
{8, 2}
Or like this
main_function(X,Y)->
A = sum(X,Y),
B = difference(X,Y),
io:format("A = ~p~nB = ~p~n", [A, B]).
The result in shell when X = 5, Y = 3 is:
A = 8
B = 2
Upvotes: 1