[Dev-C++] RE: problem calling functions
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Alan T. <ala...@3n...> - 2001-01-17 02:29:03
|
Jag,
I think you need "()" when you call your function, even if the
parameter is a void. Better yet, why don`t you pass your variables to your
functions? It is best to avoid global variables whenever possible.
Better naming of things (functions, variables, etc.) would make your
program more readable. There are also better styles for checking the
validity of input. For example, how about the following rewrite of your
program....
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
void function_1 (int int_in);
void function_2 (int int_in);
int main(int argc, char *argv[])
{
int input;
int Validated_Input = false;
while (!(Validated_Input))
{
cout <<"monkey type (1) for function 1 or (2) for function 2: ";
cin >> input;
if ((input == 1) || (input == 2))
Validated_Input = true;
else
{
Validated_Input = false;
cout << endl << " Invalid entry. Try again." << endl;
}
}
if (input == 1)
function_1(input);
else if (input == 2)
function_2(input);
system("PAUSE");
return 0;
}
void function_1 (int int_in)
{
cout <<"calling function "<<int_in << endl;
}
void function_2 (int int_in)
{
cout <<"calling function "<<int_in << endl;
}
> From: "jag" <won...@th...>
> Date: Tue, 16 Jan 2001 11:32:47 -0000
> Subject: [Dev-C++] problem calling functions
>
> Hi, can anyone tell me where i'm going wrong with my coding? The code is
at
> the end of the email. It's a simple program to practice function calls.
I
> want to enter either a number 1 or number 2 to call seperate functions.
> When the functions are called it prints a simple message to say that the
> function has been successfully called, i can n't get the program to call
the
> functions however! Can anyone advise me why?
>
> thanks in advance
> jag.
|