+ 1

Sololearn C++ Practice 76.2 Functions! Help please I’m stuck!

#include <iostream> using namespace std; //your code goes here template <class T> T myMax(T a, T b){ return b; } int main () { double x, y; cin>>x>>y; int a, b; cin>>a>>b; cout << myMax(x, y) << endl; cout << myMax(a, b) << endl; } This is my working out somehow I don’t know how to make it output the fourth one: b I tried this already: T myMax (T a, T b, T c, T d){ return b; return d; } But it did not work pls help! 🥺

6th Nov 2021, 2:48 PM
Boong Bing
2 Antworten
+ 5
template <class T> T myMax(T n1, T n2) { if (n1>n2) return n1; else return n2; } // Keep learning & happy coding :D
6th Nov 2021, 3:17 PM
SoloProg
SoloProg - avatar
+ 1
Thank you for all your support!
8th Nov 2021, 1:56 PM
Boong Bing