Breaking this down for understanding

So I have been working at this for awhile and I don't understand the div part. I understand that add sub and mul return 6 21 and -10 but cannot figure out how div returns 12.5 Could someone break this down a bit more and help me understand? Thank you

#include <iostream>
#include <iomanip>

using namespace std;

double add (double x,double y) {return x + y;}
double sub (double x,double y) {return x - y;}
double mul (double x,double y) {return x * y;}
double div (double x,double y) {return x / y;}

double F (double(*p)(double, double), int n)
{
double u = 5.0, v = -2.0;
return n * p (u,v);
}
int main()
{
cout << F (add,2) << endl;
cout << F (sub,3) << endl;
cout << F (mul,1) << endl;
cout << F (div,-5) << endl;
return 0;
}
F( div, -5 ) == -5 * div(u,v) == -5 * div( 5.0, -2.0 ) == -5.0 * -2.5 == 5.0 * 2.5 == 12.5
Last edited on
I finally understand, I was doing this wrong, but getting the right answer. Thank you so much!
Topic archived. No new replies allowed.