New course! Every coder should learn Generative AI!
Try a free lesson- 1
c++
David and Alex each have aquariums. There are 8 Rainbowfishes in David’s aquarium, and 11 Angelfishes in Alex’s aquarium. Help them exchange their fishes between them. Complete the code to swap the values of variables between aquariumDavid and aquariumAlex. Just need to know how to swap
4 Answers
+ 6
Your attempt?
+ 6
Create a temporary variable to store David's data.
int temp = DavidAquarium
DavidAquarium = AlexAquarium
AlexAquarium = temp
I'm not a c++ expert, but I think it's to understand the logic
+ 5
Mando
Think of it as a real world problem.
How can Alex & David exchange fish without getting them mixed up.
Use a 3rd tank!
David puts his fish in the 3rd tank.
Alex puts his fish in David's tank.
Fish in 3rd tank goes into Alex's tank.
Now Alex and David have swapped fish.
Think of the tanks as variables and re-assign the values.
0
Well i just declared my variables thats it