- #1
yungman
- 5,738
- 290
Hi
I just moved into Chapter 16 of Gaddis on Exception, Templates and STL. Seems like it jump a chapter. This is a partial sample from the book:
I have to complete the program as shown below but compiler doesn't like it.
I looked online on divide(), apparently it is a bigger function and I don't quite understand how to set up the parameter. I read this link:
https://en.cppreference.com/w/cpp/utility/functional/divides
Looks to be the first parameter is the numerator and second is denominator. But obviously it doesn't work.
When I ran the program, this is the error message:
I don't know how to fix it, please show me how to fix it.
Thanks
I just moved into Chapter 16 of Gaddis on Exception, Templates and STL. Seems like it jump a chapter. This is a partial sample from the book:
I have to complete the program as shown below but compiler doesn't like it.
C++:
#include <iostream>
#include <functional>
using namespace std;
int main()
{
int numerator, denominator;
double result;
cout << " Enter numerator = "; cin >> numerator;
cout << " Enter denominator = "; cin >> denominator;
double divide(int numerator, int denominator)
{
if (denominator == 0)
{
cout << " Error, cannot divide by zero.\n\n";
return 0;
}
else { return static_cast<double>(numerator) / denominator; }
}
cout << " Result of divide = " << divide << "\n\n";
return 0;
}
https://en.cppreference.com/w/cpp/utility/functional/divides
Looks to be the first parameter is the numerator and second is denominator. But obviously it doesn't work.
When I ran the program, this is the error message:
I don't know how to fix it, please show me how to fix it.
Thanks
Last edited: