Answer:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float num1,num2,product;
cout<<"Input first number: ";
cin>>num1;
cout<<"Input second number: ";
cin>>num2;
product = num1*num2;
int digits = 3;
cout << " (rounded to " << digits << " digits after the decimal point )"<< fixed << setprecision(digits) << num1 << "*" << num2 << " = " << product << "\n";
return 0;
}
Explanation:
iostream is a standard library file that contains code that allows a C++ program to display output on the screen and read input from the keyboard.
iomanip is a standard library used for formatting your output.
using namespace std means that you are going to use classes or functions from "std" namespace,
int main() is used as the entry point of the program, it contains your code and the main() is the function from where the program will start to execute.
float num1,num2,product;
you have to first declare the variables and assign them to a data type float.
cout<<"Input first number: ";
cin>>num1;
cout<<"Input second number: ";
cin>>num2;
prompt and collect inputs for num1 and num2
product = num1*num2;
calculate the product of num1 and num2
int digits = 3;
the number of digits you want after the decimal point
cout << " (rounded to " << digits << " digits after the decimal point )"<< fixed << setprecision(digits) << num1 << "*" << num2 << " = " << product << "\n";
fixed ensures that the precision that you have set will remain constant through out the code.
setprecision(digits) this allows you to set the precision