Write a function MaxMagnitude() with two integer input parameters that returns the largest magnitude value. Use the function in a program that takes two integer inputs, and outputs the largest magnitude value. Ex: If the inputs are: 5 7 the function returns: 7 Ex: If the inputs are: -8 -2 the function returns: -8 Note: The function does not just return the largest value, which for -8 -2 would be -2. Though not necessary, you may use the absolute-value built-in math function. #include <iostream>using namespace std; void MaxMagnitude(int userVal1, int userVal2) {if (abs(userVal1) > abs(userVal2)) {return userVal1;}else if (abs(userVal2) > abs(userVal1)) {return userVal2;}}/* Define your function here */ int main() { int userVal1;int userVal2;cin >> userVal1 >> userVal2;/* Type your code here. Your code must call the function. */ cout << MaxMagnitude(userVal1, userVal2) << endl;/* Type your code here */ return 0;} Please help me with this problem using c++.
Write a function MaxMagnitude() with two integer input parameters that returns the largest magnitude value. Use the function in a program that takes two integer inputs, and outputs the largest magnitude value.
Ex: If the inputs are:
5 7
the function returns:
7
Ex: If the inputs are:
-8 -2
the function returns:
-8
Note: The function does not just return the largest value, which for -8 -2 would be -2. Though not necessary, you may use the absolute-value built-in math function.
#include <iostream>
using namespace std;
void MaxMagnitude(int userVal1, int userVal2) {
if (abs(userVal1) > abs(userVal2)) {
return userVal1;
}
else if (abs(userVal2) > abs(userVal1)) {
return userVal2;
}
}/* Define your function here */
int main() {
int userVal1;
int userVal2;
cin >> userVal1 >> userVal2;/* Type your code here. Your code must call the function. */
cout << MaxMagnitude(userVal1, userVal2) << endl;
/* Type your code here */
return 0;
}
Please help me with this problem using c++.

Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images









