-
help needed
insert
Code:
#include <iostream>
using namespace std;
int computeAbsoluteValue(int number)
{
// Write your code here.
}
int main()
{
int input;
cout << "Enter a number: ";
cin >> input;
cout << "| " << input << " | = "
<< computeAbsoluteValue(input)
<< endl;
return 0;
}
Fill up the computeAbsoluteValue function so that it will return the absolute value of a number. The absolute value of a number is its numerical value without regard to its sign (eg. 8 is the absolute value of both 8 and -8). The output of the program should look like these:
Sample Output 1:
Enter a number: -12
|-12| = 12
Sample Output 2:
Enter a number: 5
|5| = 5
* can anyone help me with this??
-
-
-
It's a pretty simple algorithm. If the number is greater than or equal to zero, return that number. If the number is less than zero, multiply the number by negative one and return the result.
This can be done in one line of code using the ?: operator like vart suggested, but I'd imagine it would be a lot easier for you to just use if/else statements instead.
-
i think i get the idea.. thx.. ^^
-
Only one more thing, please but some more suggestive titles, like: Help in Insert, Insert Problems...
And but the code and the result in separated code tags please!
Thanks!