In: Computer Science
Write a single C++ statement to accomplish each of the following. (6 pts)
a. To read an integer from the user at the keyboard we use cin object of the iostream class. cin object is used with the >> operator to receive a stream of characters. General Syntax for cin operator is:
cin >> variableName;
For this problem we will first declare an integer variable with name age and then use the cin object to read an integer from the user at keyboard.
int age;
cin >> age;
Above statement will read an integer from the user at the keyboard and store the value entered in an integer variable age.
b. To get the products of integers we use the multiplication operator *. To solve this problem we will declare 3 variables of integer type x, y, z. We will initialize x, y, z with some random value and then we declare an integer variable result whose value will be equal to multiplication of x, y and z.
int x, y, z;
x = 3; y = 4; z = 7;
int result = x*y*z;
Above statement will compute the product of the 3 integers contained in variables x, y and z and assign the result to the variable result.
In above statement I have taken the value of x,y and z as 3,4 and 7 respectively. You can change it to any value you want or can change it to read value from the user at the keyboard by replacing the second line with
cin >> x >> y >> z;
If you're still having any doubt then please feel free to ask in the comment section.