Tuesday 21 July 2020

10. 2.16 (Arithmetic) 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.

10. 2.16 (Arithmetic) 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.

#include <iostream> // allows program to perform input and output
// function main begins program execution
using std::cout; // program uses cout
using std::cin; // program uses cin
using std::endl; // program uses endl
int main()
{
 int number1; // first integer
 int number2; // second integer
 int sum; //holds sum
 int product; //holds product
 int difference; //holds difference
 float quotient; //holds quotient
 cout << "Enter two integers: "; // prompt user for data
 cin >> number1 >> number2; // read two integers from user
 
 sum=number1+number2;
 cout<<"Sum is: "<<sum<<endl;
 
 product=number1*number2;
 cout<<"Product is: "<<product<<endl;
 
 difference=number1-number2;
 cout<<"Dofference is: "<<difference<<endl;
 
 if(number2!=0){
  quotient=(float)number1/number2;
  cout<<"Quotient is: "<<quotient<<endl;
 }
} // end function main

No comments:

Post a Comment