hi
everyone out there i was trying out to make a procedure in mel which should take two numbers as inputs from the user and should provide the sum of its addition & subtraction ............. means in one procedure only i want to perform addition & subtraction both but i also want to give a choice to the user to decide weather he wants to add the two numbers or want to subtract the two ...................... but right now i am unable to do so, means i am able to get the result of both addition & subtraction in one go or either no result, but i don't want to do it like that instead i want it to work on step by step basis on the two given numbers.......... now i am posting you few of my codes pls tell me where exactly i am doing the mistake .............by step by step i mean that if the user want to add he should only get the addition result and if he wants to subtract then only the subtraction result...........
with regards
sid's
//procedure1 here i am able to add & subtract only when the number is greater or smaller from the other number but i //don't want to do like that.
proc numbers(int $a,int $b)
{
if($a<$b)
{
int $o = $a+$b;
print ($o+"\n");
}
else if($a>$b)
{
int $x = $a-$b;
print($x+"\n");
}
}
numbers(44,22);
//procedure2 here also i am doing the same thing but with one more addition of if the numbers are equal.
proc numbers(int $a,int $b)
{
if($a<$b)
{
int $o = $a+$b;
print ($o+"\n");
}
else if($a>$b)
{
int $x = $a-$b;
print($x+"\n");
}
else if($a==$b)
{
int $g = $a+$b;
print($g+"\n");
}
//procedure3 here i am comparing a second variable with add or subtract but i am not getting any result & am totally //confused what to do next
proc calc(int $a, int $b)
{
int $choice;
if ($choice == "add")
{
$choice = $a+$b;
print($choice+"\n");
}
else if ($choice == "subtract")
{
$choice = $a-$b;
print($choice+"\n");
}
}
}
numbers(44,44);
//procedure4 here i am trying it by another conditional statement but again not getting any result & is very confused
proc int calc(int $a, int $b)
{
int $sum1;
switch ($sum1)
{
case 1:
$sum1 = $a+$b;
print($sum1+"\n");
case 2:
$sum1 = $a-$b;
print($sum1+"\n");
}
return $sum1;
}
as you all can see my codes i know that i am doing a very silly mistake somewhere but i don't know where exactly and am unable to solve the problem so need a help on the same ............ kindly pls someone out there help me on the same as i am stuck right now...............
with regards
sid's