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++.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter6: User-defined Functions
Section: Chapter Questions
Problem 22PE
icon
Related questions
Question

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++.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr