Reputation: 27
I tried several time to find where is the problem, but I can not find any thing.So, could anyone help me to find the problem and why I can not see a result?
It might seem stupid question, but I new to programming world :)
This is my code :
#include <iostream>
using namespace std;
// There is the declraction of all functions
float max();
float min();
// This is the main program
int main ( int argc, char ** argv )
{
// Here you can find max
max(504.50,70.33);
// Here you can find min
min(55.77, 80.12);
return 0;
}
// This is the max function
int max(float a, float b){
float theMax;
if (a>b) {
theMax = a;
cout <<theMax ;
}
else{
theMax = b;
cout << b;
}
return theMax;
}
// This is the min function
int min( float c, float d){
float theMin;
if (c >d ) {
theMin =c;
cout << theMin;
}
else {
theMin =d;
cout << theMin;
}
return theMin;
}
Upvotes: 2
Views: 62
Reputation: 179981
You're calling std::max
and std::min
. That's because you wrote using namespace std
, and did not declare your own min
and max
prior to using them. (You did declare two other min
and max
functions, but those take zero arguments, not two). So, when the compiler sees max(504.50,70.33);
the only candidate is std::max
.
Upvotes: 1
Reputation: 66441
You declare these overloads:
float max();
float min();
which are functions that take no arguments and return float
.
You're calling
max(504.50,70.33);
and
min(55.77, 80.12);
which are functions that takes two double
s and may or may not return anything.
These match std::max
and std::min
, not the prototypes you declared.
You then define
int min( float c, float d){
which also doesn't match the prototypes you declared.
In other words, these functions are unknown in main
, and the functions that are actually called are std::min
and std::max
.
Don't use using namespace std;
- what you save in typing is lost in clarity and debugging.
You should also rename the functions - it's not a good idea to reuse standard library names.
Upvotes: 1