c++ | Sololearn: Learn to code for FREE!
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

2nd Oct 2021, 8:27 AM
Mando
Mando - avatar
4 Answers
+ 6
Your attempt?
2nd Oct 2021, 8:28 AM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 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
2nd Oct 2021, 8:31 AM
Erlénio.RS
Erlénio.RS - avatar
+ 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.
2nd Oct 2021, 8:48 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
Well i just declared my variables thats it
2nd Oct 2021, 8:31 AM
Mando
Mando - avatar