Kodewick
Start learning →
Basic←→0 / 60

Swap the cups

#035BasicReferencesStrings4 min

The magician swaps two cups around. Write swap_cups(a, b) so that a and b trade what's in them. Both are references, so afterwards left and right in after_swap have swapped too.

Examples
after_swap("ball", "empty")→'empty ball'
after_swap("red", "blue")→'blue red'
The functionstring after_swap(string left, string right)
main.cpp
#include <string>
using namespace std;

void swap_cups(string &a, string &b) {
    // your code here: swap a and b
}

string after_swap(string left, string right) {
    swap_cups(left, right);
    return left + " " + right;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.