I keep getting these 2 errors in my code
In function 'int main()': error: invalid initialization of non-const reference of type 'int&' from a temporary of type 'int' error: in passing argument 1 of 'void swapInt(int&, int&)'
but the real problem I’m having is with swapInt. I need to take in 2 ints
and then switch their values with their parameters so what was once a is now b
and what was once b is now a. please help!
void swapInt (int &a, int &b);
int main() {
int a = 1;
int b = 2;
swapInt(1, 2);
cout << a << " " << b;
return 0;
}
void swapInt (int &a, int &b) {
int c = a;
a = b;
b = c;
//cout << a << " " << b;
}
Your function works with the address of variables, but you’re passing in number constants. You need to pass in the variables like: