1st Code :
#include
using namespace std;
int max(int first, int second){
return(first>second) ? first: second;
}
int main(){
int larger=max(1,2) ;
cout<<larger;
return 0;
}
2nd code:
#include
using namespace std;
int main(){
cout<<"Enter two integers x and y: ";
double first;
double second;
cin>>first;
cin>>second;
cout<<first+second;
return 0;
}
1 Like
Create a header file and save your function(s) in that file. Demonstrated in C++ Part 3: Classes.
1 Like
I not understand what you telling
Look here:
https://cplusplus.com/articles/Gw6AC542/
It is also explained in Part 3 of the C++ course.
1 Like
Im new here, I think the question was he wants to integrate the two codes one having a functions and the other getting inputs from user. If thats the case, here is my working code. Change function name from max to maxValue to avoid conflict with Standard Library std::max function.
#include
using namespace std;
int maxValue(const int* first, const int* second) {
return((*first > *second) ? *first: *second);
}
int main() {
int first;
int second;
cout<<"Enter two integers x and y: ";
cin>>first;
cin>>second;
int larger = maxValue(&first, &second);
cout<<larger;
return 0;
}