1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ivanzaharov [21]
2 years ago
5

8.19 LAB: Max magnitude Write a function max_magnitude() with two integer input parameters that returns the largest magnitude va

lue. 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 in c language
Computers and Technology
1 answer:
AysviL [449]2 years ago
7 0

Answer:

#include <iostream>

using namespace std;

int max_magnitude(int firstValue, int secValue)//taking two itnerger inputs

{

if (firstValue > secValue)//using if condition

 return firstValue;

else

 return secValue;

}

int main()

{

int firstVal, secVal, finalVal;

cout << "Enter your first value: " << endl;

cin >> firstVal;

cout << "Enter your second value: " << endl;

cin >> secVal;

finalVal = max_magnitude(firstVal, secVal);//calling function

cout << "The greater value is: " << finalVal << endl;

return 0;//terminating program

}

Explanation:

This exercise is for you to understand how to make and call functions. Functions are a way to basically clean the main code. If you read the main code, you can intuitively tell that the finalVal variable is being assigned a max magnitude of some kind. The program would have run absolutely fine if i simply copy pasted the function inside my main. But imagine, if I had to call this function 1000 times, it would've looked quite ugly.

Secondly, there is a certain way how functions work. Function can, and may not take arguments, depending on what it is supposed to do. for example in this case, the function is taking two arguments, because it needs two compare two values from the main function. Now imagine if I made a function to say, exit the program. I would need any arguments. I would simply call the function and it would say 'return 0' and the program will end.

Thirdly, functions may or may not RETURN a value. I our case if you look closely, our function is called 'int' max_magnitude. The int is signalling what type it will return. This means that when the function completes its processing, it will return to where it was called from and give back the value it ended on.

You might be interested in
Which of the following is NOT something you can specify in the bullets and numbering dialog box?
geniusboy [140]

type tool?? not postive


4 0
3 years ago
What are some examples of environmental technology
Zarrin [17]
Some examples of environmental technology is recycling.
3 0
3 years ago
A large retail company hires several new joiners and would like to incorporate Virtual Reality (VR) into their onboarding proces
Volgvan

 The best utilize VR for this purpose is a simulated experience interacting with customers.

<h3>What is Virtual reality (VR)?</h3>

Virtual Reality (VR) is known to be a kind of computer created environment that is made up of scenes and objects that seems to be real.

It is a type of reality that makes its  user feel they are inside their surroundings. This environment is said to be seen via device known as a Virtual Reality headset or helmet.

See options below

Which approach would best utilize VR for this purpose?

an animated video that covers compliance training

a 360-degree online tour of the retail store

an application that enables online contract signing

a simulated experience interacting with customers

Learn more about Virtual Reality (VR) from

brainly.com/question/26705841

4 0
2 years ago
What is an active cooling solution for a PC?
mina [271]
Reduce the speed of the CPU
6 0
3 years ago
Read 2 more answers
Lenders always accept applications for credit
LenKa [72]
The correct answer to the question that is being stated above is FALSE.

The statement is false because lenders do not always accept applications for credit. Lenders always consider credit history of the applicant. If the applicant has a good credit history background, then he qualifies.
3 0
3 years ago
Other questions:
  • Julie bought a house for $315,000 and has a $285,000 mortgage. she claims she has $315,000 in equity. is she correct? if not, ho
    12·2 answers
  • Your friend sees an error message during Windows startup about a corrupted bootmgr file. He has another computer with a matching
    12·1 answer
  • Computer Architecture
    7·1 answer
  • Media messages are communicated through which of the following:
    8·2 answers
  • What is one of the benefits of using templates for your email marketing campaigns?
    10·1 answer
  • Software enables users to create documents
    13·1 answer
  • Which of the following defines a network
    7·1 answer
  • Micheal is the project manager in a company. He wants his organization to use technology for higher revenue and productivity. Wh
    13·1 answer
  • Why do computers use binary code?
    12·2 answers
  • A good information that contains the facts necessary for decision makers to solve a problem is characterized by the __________.
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!