Question
Hello, I need help solving this Lab simulation, It uses Max magnitude for function statements and I am very new at coding on so I
Hello, I need help solving this Lab simulation, It uses Max magnitude for function statements and I am very new at coding on so I need help solving it. It is very difficult. It is very confusing since the there are multiple inputs and on can only code it once.
a function MaxMagnitude with two input parameters, that returns the largest-magnitude value. If the inputs are 5 7, the function returns 7. 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.
Use the function in a program that takes two integer inputs, and outputs the largest-magnitude value.
#include
using namespace std;
int main() {
/* your code here. */
return 0;
}
Here is a clue my classmate gave to me
In the code sample below, you are implementing a function that would find the largest value of the two entered.
The code also implements the check for absolute value. I hope this helps.
I am using function prototype here, you do not have to use function prototype, but then, you would need to define/implement theMaxMagnitudefunction first. By using a prototype, you could place the function implementation anywhere in the code, before or after main implementation.
#include
usingnamespacestd;
intMaxMagnitude(int,int);//Function prototype, consider this like declaring a variable except this is a function
intmain() {
//declare a variable x of type integer
//declare a variable y of type integer
//declare a variable largest of type integer
//usecinto get x from keyboard
//usecinto get y from keyboard
//call the function and pass x and y as its argument and assign to largest
//print the value of largest on this line
return0;
}
intMaxMagnitude(intx,inty) {//implement the function
//declarexAbsof type integer
//declareyAbsof type integer
//below is how you would find absolute value
if(x< 0) {
//assign -x toxAbs
}
else
{
//assign x toxAbs
}
if(jQuery224044473567614431_1589253479517?) {//check to see if y is less than zero
//assign -y toyAbs
}
else
{
//assign y toyAbs
}
if(???) {//check to see ifxAbsis greater thanyAbs
returnx;
}
else{
returny;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started