need quicky help..

Joined
Sep 6, 2007
Messages
7
Reaction score
0
i was trying to do number swap..but in vain..

#include<iostream>

using namespace std;


function change(int *a , int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}

int a=1, b=10;
int main()
{

cout << "a is "<<a<<" and b is "<<b<<endl;

change(&a, &b);

cout << "a becomes "<<a<<" and b becomes "<<b<<endl;
}

---------------
6 `function' does not name a type
20 `change' undeclared (first use this function)
---------------

i've no ideas... plz give some comments. great thx.
 
Last edited:
Joined
Sep 6, 2007
Messages
5
Reaction score
0
No function in C or C++ has the keyword function but it should have a return type. So, do try this

#include<iostream>
#include<conio.h>
using namespace std;
void change(int *a , int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
int a=1, b=10;
int main()
{
cout << "a is "<<a<<" and b is "<<b<<endl;
change(&a, &b);
cout << "a becomes "<<a<<" and b becomes "<<b<<endl;
getch();
return 0;
}
 
Joined
Sep 6, 2007
Messages
7
Reaction score
0
Yippee

YES ! It worked ! Thank you.

BTW, conio.h seems of C header. Does it have an equivalent in C++ ? If I'd like to replace conio.h and getch() with their C++ counterparts, what should I write instead ?
 
Last edited:
Joined
Sep 6, 2007
Messages
5
Reaction score
0
Re: Alternate for conio.h in C++

Ofcourse you can use conio.h in C++ but some compilers/systems wont support but you can always use system("pause"); irrespective of any systems/compilers, for which the definition is in stdlib header file, So you need to include that too.

regards,
*KAMAL*
 
Joined
Sep 6, 2007
Messages
5
Reaction score
0
Re: Alternate for conio.h in C++

:) Ofcourse you can use conio.h in C++ but some compilers/systems wont support but you can always use system("pause"); irrespective of any systems/compilers, for which the definition is in stdlib...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top