200k views
4 votes
Write a program that asks the user to enter two numbers,obtains the two numbers from the user and prints the sum,product,

difference, and quotient of the two numbers

User Nandop
by
7.4k points

1 Answer

3 votes

Answer:

#include<iostream>

using namespace std;

//main function

int main(){

//initialization

float a1,a2;

//display the message

cout<<"Enter the first number: ";

cin>>a1; //store the value

cout<<"Enter the second number: ";

cin>>a2; //store the value

//display the calculation result

cout<<"The sum is: "<<a1+a2<<endl;

cout<<"The Subtraction is: "<<a1-a2<<endl;

cout<<"The product is: "<<a1*a2<<endl;

cout<<"The Quotient is: "<<a1/a2<<endl;

}

Step-by-step explanation:

Create the main function and declare the two variables of float but we can enter the integer as well.

display the message on the screen and then store the input enter by the user into the variable using the cin instruction.

the same process for second input as well, display the message and store the input.

after that, print the output of the calculation. the operator '+' is used to add the two numbers like a1+a2, it adds the number stored in the variable.

similarly, the subtraction operator is '-', product '*' and quotient operator '/'.

and finally, we get the desired output.

User Ikechukwu
by
6.0k points