Can anyone please tell where I am doing mistake in my code but still I am getting error while my execution time | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone please tell where I am doing mistake in my code but still I am getting error while my execution time

#include<iostream> using namespace std; //fuction declartion void swap(int x,int y); int main() { //local variable declartion int a =100; int b=200; cout<<"before swap value of a:"<<a<<endl; cout<<"before swap value of b is:"<<b<<endl; // calling a function to swap the values swap(a,b); cout<<"after swap value of a:"<<a<<endl; cout<<"after swap value of b is:"<<b<<endl; return 0; }

8th Jun 2022, 1:17 PM
Sunilsingh Nagarkoti
8 Answers
+ 3
A) You use the built-in swap function. Then don't redeclare it in the head of the script. B) You meant to write an own swap function. Then the declaration is missing.
8th Jun 2022, 1:42 PM
Lisa
Lisa - avatar
+ 1
Remove void swap(int x, int y); in order to use the built-in function
8th Jun 2022, 2:48 PM
Lisa
Lisa - avatar
0
I do not see where you are adding any logic to the swap function. You're just passing in parameters.
8th Jun 2022, 1:24 PM
Justice
Justice - avatar
0
Were is the function defined? Please LINK your complete code: Go to Code section, click +, select the programming language, insert your code and save. Come back to this thread, click +, Insert Code, sort for My Code Bits, select your code.
8th Jun 2022, 1:26 PM
Lisa
Lisa - avatar
0
I did everything bro this is my whole code but I am not getting output swapping values of a and b if you know about some functions where I am doing mistake please tell me
8th Jun 2022, 1:31 PM
Sunilsingh Nagarkoti
0
But I did point something out. I said that you're only passing in parameters, but you're not doing anything with the parameters that you're taking in. You need to tell the computer what you want to do with the parameters that you're passing in. It can't read your mind and doesn't know what "swap" means yet until you give it clear instructions.
8th Jun 2022, 1:33 PM
Justice
Justice - avatar
0
I am not getting your point can you write it down in the text maybe I understand better
8th Jun 2022, 2:31 PM
Sunilsingh Nagarkoti
0
Okay thnx
8th Jun 2022, 2:55 PM
Sunilsingh Nagarkoti