Passing Value to function

Could anyone tell me why I am getting such weird numbers passed to my function?
Here is the code.

#include <iostream>
#include <stdio.h>

using namespace std;

int LCF(int m, int n);


int main( )
{
int m; int n;
cout << endl;
cout <<"Enter the smallest integer";
cin >> m;
cout <<"Enter the greatest integer: ";
cin >> n ;
cout << "m = " << m << endl <<"n = " << n << endl;
if( n >= m ){
cout <<"GOOD JOB! You followed directions!";
}
else{
cout <<"You DID NOT follow directions" << endl;
}
cout << endl;

LCF(m,n);

return 0;
}


int LCF( int, int )
{
int m; int n;
cout << endl;
cout << "m = " << m << endl <<"n = " << n << endl;


return 0;
}

Change the definition of the function the following way

1
2
3
4
5
6
7
int LCF( int m, int n )
{
   cout << endl;
   cout << "m = " << m << endl <<"n = " << n << endl;

   return 0;
}
Last edited on
Ahh, thanks. I thought I tried that but I guess not.
Why are you return type int... no need of that just make it
1
2
3
4
void LCF(....)
{
   // remove return 0;
}
Eventually I am going to return something. I just stripped it down to make it easier to understand my problem. It's just been over a year since I did anything in C, and I haven't learned C++ yet, so I am just trying to do some basic things to refresh my memory of C, so I can start learning C++. I appreciate your help. Thank you..
Well Kyle,

It seems If you want to return something later, it means you will change your function. But i Hope you understand following things well ...

Also kyle, you should be using block using editor around the code you post, that will help you get better answer...

1
2
3
4
5
6
7
8
9
10
11
Function_return_Type   Function_Name
(
function_parameter1,
function_parameter2,
....
)
{
// Function body

return Function_return_Type;
}


But now let's say, if you don;t want to return anything from function, just make it

1
2
3
4
5
6
7
8
9
10
void   Function_Name
(
function_parameter1,
function_parameter2,
....
)
{
// Function body

}
Last edited on
Block editor? I did not know that. Ok, I will look into that.
Topic archived. No new replies allowed.