Question: This is a fill in the code type: // FILL IN THE CODE - Write a program to multiply 2 numbers, print out the results
This is a fill in the code type:
// FILL IN THE CODE - Write a program to multiply 2 numbers, print out the results and print out the original numbers in ascending order.
#include
using namespace std;
int main() {
int num1; // holds 1st number
int num2; // holds 2nd number
int result; // holds result of multiplication
int *num1Ptr = nullptr; // int pointer which will be set to point to the 1st number
int *num2Ptr = nullptr; // int pointer which will be set to point to the 2nd number
cout << "Please input the 1st number" << endl;
cin >> num1;
cout << "Please input the 2nd number" << endl;
cin >> num2;
// Fill in code to make num1Ptr point to num1 (hold its address)
// Fill in code to make num2Ptr point to num2 (hold its address)
num1Ptr = &num1;
num2Ptr = &num2;
// Fill in code to find the result by using only the pointer variables
result = *num1Ptr * *num2Ptr;
cout << "The result is " << result << endl;
if (*num1Ptr > *num2Ptr)
cout << "The 1st number is greater than the 2nd number" << endl;
else if (*num2Ptr > *num1Ptr)
cout << "The 2nd number is greater than the 1st number" << endl;
else
cout << "The 2nd number and 1st number are the same" << endl;
return 0;
}
I have filled out all the ones that needs to be filled.
It says "Write a program to multiply 2 numbers, print out the results and print out the original numbers in ascending order."
It's already printing out the results of the two numbers multiplied, but I'm not quite sure how to print put the original numbers in ascending order. Let's say, the user inputs 8 then 10. it should display 8, 10. Thank you.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
