Honestly depends how you would code it. If you consider how language tends to refer to the last thing you talked about without re stating its name it makes sense to use a tmp used to remember that.
In which case you have something like that (in some C++ like language)
==================
class product{
...
}
int main(){
goto(market);
buy(milk, 1);
if(isAvalaible(product* tmp = new product("eggs")) , market){
buy(&tmp, 6);
}
return 0;
}
=================
Now that would get the expected result.
And if you don't consider adapting your code to the language you use then you would have an error:
"error in buy function : not enough arguments, expected 2 got 1
because you buy 1 bottle of milk BEFORE entering the if condition, and then you have call the buy function with only one argument : 6.
I reread what I just wrote and arrived to the conclusion that I was funnier at parties before I learned computer science.
Java:
public class groceriesList{
public static void main( String[] args ) {
boolean hasMilk = true;
int numMilk = howMuchMilk(hasMilk);
}
public int howMuchMilk(boolean m){
if(m){
return 6;
} else {
return 1;
}
}
}
Probably messed up somewhere, I'm on my phone
In which case you have something like that (in some C++ like language)
==================
class product{
...
}
int main(){
goto(market);
buy(milk, 1);
if(isAvalaible(product* tmp = new product("eggs")) , market){
buy(&tmp, 6);
}
return 0;
}
=================
Now that would get the expected result.
And if you don't consider adapting your code to the language you use then you would have an error:
"error in buy function : not enough arguments, expected 2 got 1
because you buy 1 bottle of milk BEFORE entering the if condition, and then you have call the buy function with only one argument : 6.
I reread what I just wrote and arrived to the conclusion that I was funnier at parties before I learned computer science.
public class groceriesList{
public static void main( String[] args ) {
boolean hasMilk = true;
int numMilk = howMuchMilk(hasMilk);
}
public int howMuchMilk(boolean m){
if(m){
return 6;
} else {
return 1;
}
}
}
Probably messed up somewhere, I'm on my phone