In: Computer Science
Write in C++
Print the following heading (should be in heading function)
Welcome to Reference parameters
2 ) ask the user for 2 numbers (should be in main)
3 ) Calculate the sum and product of the numbers using reference parameters (should be in getAnswer function)
4 ) Print the sum and product of the numbers in the following format: (should be in printmessage function)
Here is the function you need
Function name | Parameters | Return Type
heading | N/A | void
getAnswer | lnumber1, number2, sum, product | void
printmessage | sum, product | void
Sum: <sum>
Product: <product>
Example:
Enter a number: 5
Enter another number: 2
Sum: 7
Product: 10
please refer to bleow attached photos for clear understandign and implementation of the program :
code :
#include <iostream>
using namespace std;
void getAnswer(int a , int b , int &product , int &sum){
sum = a + b;
product = a * b;
}
void printmessage(int sum , int product){
cout<<"Sum : "<<sum<<endl;
cout<<"Product : "<<product<<endl;
}
int main(){
int a,b,sum,product;
cout<<"Enter one number : ";
cin>>a;
cout<<"\nEnter another number : ";
cin>>b;
getAnswer(a , b , product , sum);
printmessage(sum , product);
}