### explanation needs

can some body explain to me this code using comments

what part of the function makes it makes the program print the largest number?

from my understand `int`is used for integer and `double` is for decimal.

why can't we just use `double` for every thing?

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455`` ``````#include using namespace std; int myMaxFunc(int n1, int n2); double myMaxFunc(double n1, double n2); double myMaxFunc(double n1, int n2); double myMaxFunc(int n1, double n2); // PURPOSE OF THE PROGRAM // takes 4 numbers and prints // the largest number. int main() { double maxDbl = myMaxFunc(1, 1.5); //int maxInt = myMaxFunc(1, 1); /*cout << "Enter the first number: "; int num1; cin >> num1; cout << "Enter the second number: "; int num2; cin >> num2; cout << "Enter the third number: "; int num3; cin >> num3; cout << "Enter the last number: "; int num4; cin >> num4; int maxNum = myMaxFunc(num1, num2); maxNum = myMaxFunc(maxNum, num3); maxNum = myMaxFunc(maxNum, num4); cout << "The maximum number is " << maxNum << endl; */ system("PAUSE"); return 0; } double myMaxFunc(double n1, int n2) { return myMaxFunc(n1, (double)n2); } double myMaxFunc(int n1, double n2) { return myMaxFunc((double)n1, n2); } double myMaxFunc(double n1, double n2) { if (n1 > n2) return n1; else return n2; } int myMaxFunc(int n1, int n2) { if (n1 > n2) return n1; else return n2; }``````
Last edited on
Topic archived. No new replies allowed.