|
From: Daniel G. <sp...@ho...> - 2002-12-06 12:33:01
|
You have to use forward declaration.
At the moment, when the function is called the compiler says
"what's this? functionTwo()? I don't know about that"
Either write out your functions before your main function, like
#include <iostream.h>
int FunctionTwo( int Input )
{
Input = 365;
return Input;
}
int main()
{
int Input = 0;
FunctionTwo( Input );
cout << "End";
return 0;
}
Or type them all out in to a header file, then #include it.
// in the header file (Functions.h)
int FunctionTwo( int Input )
{
Input = 365;
return Input;
}
// in the main (.cpp) file
#include <iostream.h>
#include "Functions.h"
int main()
{
int Input = 0;
FunctionTwo( Input );
cout << "End";
return 0;
}
P.S. I know that's not the greatest example of coding, but I'm keeping it
simple as I got confused by examples when I started.
If you need help, post again!
>From: Dondolo Mpho <MDo...@OL...>
>To: 'dev-cpp-users-list' <dev...@li...>
>Subject: [Dev-C++] FunctionCalling()
>Date: Fri, 6 Dec 2002 13:05:20 +0200
>
>Hi all,
>
>I am in the process of learning C++. I have been practising, writing my own
>functions and using main() only to call those function. I also use those
>functions to call up other function....
>
>//e.g.: function (1)
>
>void FuctionOne(void)
>{
>int Answer
>cout<<"Are you ready...<press 1 for yes and 2 for no> ";
>cin>>Answer;
> if(Answer==1)
> {
>cout<<"\nI am glad that you are";
>}
>
>else
> {
> FuctionTwo();
> }
>
>}
>
>//Here I have my
>//FunctionTwo
>
> Now I find that the compiler flags an
>error msg that FunctionTwo has not been declared. it only works when I take
>FunctionTwo() and put it on top of
> FunctionOne()....i am I doing
>something
>wrong? The thing is I might decide halfway through my functions That i want
>function x to call function
> y. Now If i have to readjust my
>functions half way through, i will loose track of what I am
>doing.....Please
>help anybody
>
>
>Mpho Dondolo
>Support Analyst
>CSC Computer Sciences (South Africa) (Pty) Ltd
>Tel: +27 21 503030164
>cell: +27 84 3371468
>Fax: +27 21 5095619
>Email:MDo...@ol...
>Email: MDo...@cs...
>
>
_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail
|