### Help 'reading' some code.

Here is some code, I was wondering if someone could explicitly describe what is going on throughout the code so I could better understand it. I have tried but I keep running into issues. Such as what do a and b refer to in the first, second, and third calls to swap(a,b)? Also I have a non-void error when trying to run this. Some clear explanation would help me solve further code.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748`` ``````#include #include // Required for setw() setprecision(), fixed. #include using namespace std; void swap(string& a, string& b) { string temp; temp = a; a = b; b = temp; } int three_card_monte(string card1, string card2, string card3) { swap(card1, card2); swap(card2, card3); swap(card1, card3); if (card1 == "queen") return 1; else if (card2 == "queen") return 2; else if (card3 == "queen") return 3; } int main() { string first = "queen"; string second = "king"; string third = "ace"; int guess; int location; location = three_card_monte(first, second, third); cout << "Where's the Queen ( 1, 2 or 3 ) ? "; cin >> guess; if (guess == location) cout << "Congratulations!" << "\n"; else cout << "Better luck next time, it was number " << location << "\n"; return 0; } ``````
` Such as what do a and b refer to in the first, second, and third calls to swap(a,b)?`

Always the same. `a` is the first parameter passed in, `b` is the second.
Topic archived. No new replies allowed.