I was wondering if what I have done is correct or not. Here's what my book says to do:
"Write a function template that accepts an argument and returns its absolute value. The absolute value of a number is its value with no sign. For example, the absolute value of -5 is 5, and the absolute value of 2 is 2. Test the template in a simple driver program."
This is the code that I've done:
// This program displays the absolute value of an entered number.
#include <iostream>
#include <cmath>
#include <conio>
using namespace std;
template <class T>
T abs(T val1)
{
return val1;
}
int main()
{
double num1;
cout << "Enter a number, and I will display the absolute value of that number: ";
cin >> num1;
cout << "The absolute value of the enterend number is: " << abs(num1) << endl;
getch();
return 0;
}