SummaryIn this lab, you complete a partially written C++ program that includes a function named multiplyNumbers() that multiplies two int values to find their product.Three ints should be passed to the multiplyNumbers() function, the two numbers to be multiplied (num1 and num2) should be passed by value, and another int (product) to hold the product of the two numbers should be passed by reference, enabling the multiplyNumbers() function to change its value.The source code file provided for this lab includes the necessary variable declarations and input and output statements. Comments are included in the file to help you write the remainder of the program.Instructions:Open the source code file named MultiplyTwo.cpp using the code editor.Write the multiplyNumbers() function, the function declaration, and the function call as indicated by the comments.
Declare the method prototype using:
void multiplyNumbers(int x, int y,int &product);
Call the function using:
multiplyNumbers(num1, num2,product);
Lastly, the method is as follows:
void multiplyNumbers (int x, int y,int &product) {
product = x * y;
return; }
Explanation:
Declare the method prototype using
void multiplyNumbers(int x, int y,int &product);
Call the function using
multiplyNumbers(num1, num2,product);
The method is as follows; the & written in front of product implies that product is passed by reference
void multiplyNumbers (int x, int y,int &product) {
This calculate the product
product = x * y;
This returns nothing
return; }
Comments
Leave a comment