#include <iostream>
usingnamespace std;
int high(int first, int second, int third, int fourth)
{
int x = 0;
int y = 0;
int finale = 0;
x = sum(first, second);
y = sum(third, fourth);
finale = sum(x, y);
return finale;
}
int sum(int x, int y)
{
if (x>y)
{
int t = 0;
t = x;
return t;
}
else
{
int t = 0;
t = y;
return t;
}
}
int main()
{
int sum(int, int);//function prototype
int high(int, int, int, int);
int total = 0;
total = high(2, 5, 3, 4);
int total1 = 0;
total1 = sum(5, 6);
cout << total1;
char aaa;
cin >> aaa;
return 0;
}
What you have here is even though the functions come before "main" order does sometimes make a difference.
What has happened here is that the function"high" is calling the function "sum", but the compiler has yet to see this function definition.
You could change the order of the two functions or add prototypes before the functions.
Hint: In the future include the error messages you get that you do not understand, so whom ever reads the post will know what the problem is. Some will see the problem by looking at the code others, like me, may not see it right and have to load the program and compile it to see what you did not tell in your post.
I found your function prototypes in "main" by the time the compiler would reach "main" it is to late for the prototypes. they should be after the using line that is best not to use.
Once I moved the prototypes from main to above the function definitions the errors went away.
int highest(int first, int second, int third, int fourth)
{
return high(high(first,second),high(third,fourth);
}
int high(int x, int y)
{
return (x>y)?x:y;
}
It's confusing but try analyzing it.
-> Keep in mind that function prototypes must be declared right after the definition section (where #include<headerfile> go) and in global space
-> Either that or you could put your two functions at the bottom of the program and declare your prototype inside the main itself. That works too.