1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
yuradex [85]
3 years ago
14

Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It sh

ould then output the numbers, the operator, and the result. For division, if the denominator is zero, output an appropriate message. Limit the supported operations to -/ *and write an error message if the operator is not one of the supported operations. Here is some example output:3 4
Computers and Technology
1 answer:
IgorC [24]3 years ago
5 0

Answer:

The cpp calculator program is as follows.

#include <iostream>

using namespace std;

int main()

{

   //variables to hold two numbers and operation

   int num1;

   int num2;

   char op;

   char operations[] = {'-', '/', '*'};

   std::cout << "Enter first number: ";

   cin>>num1;

   std::cout << "Enter second number: ";

   cin>>num2;

   do

   {

       std::cout << "Enter the operation to be performed(-, /, *): ";

       cin>>op;

       if(op!=operations[0] && op!=operations[1] && op!=operations[2])

           std::cout << "Invalid operator." << std::endl;

   }while(op!=operations[0] && op!=operations[1] && op!=operations[2]);

   std::cout<< "Numbers are "<< num1 <<" and "<< num2 <<std::endl;

   std::cout << "Operator is " <<op<< std::endl;

   if(op==operations[0])

       std::cout << "Result is "<< num1-num2 << std::endl;  

   if(op==operations[1])

       if(num2==0)

           std::cout << "Denominator is zero. Division cannot be performed." << std::endl;

       else

           std::cout << "Result is "<< num1/num2 << std::endl;

   if(op==operations[2])

           std::cout << "Result is "<< num1*num2 << std::endl;

   return 0;  

}

OUTPUT

Enter first number: 12                                                                                                                    Enter second number: 0                                                                                                                         Enter the operation to be performed(-, /, *): +                                                                                                Invalid operator.                                                                                                                              Enter the operation to be performed(-, /, *): /                                                                                                Numbers are 12 and 0                                                                                                                           Operator is /                                                                                                                                  Denominator is zero. Division cannot be performed.

Explanation:

1. Declare two integer variables to hold the numbers.

int num1;

int num2;

2. Declare one character variable to hold the operation to be performed.

char op;

3. Declare one character array to hold all the operations.

char operations[] = {'-', '/', '*'};

4. User input is taken for the two numbers followed by the operation to be performed.

5. Validation is applied for incorrect operation entered by the user. This is done using if statement inside a do-while loop.

6. Once the correct input is obtained, the calculator program performs the required operation on the numbers. This is done using if statements.

7. If the denominator number is zero for division operation, a message is displayed to the user.

8. The numbers followed by the operation chosen by the user are displayed.

9. The result of the operation is computed and displayed.

You might be interested in
What medical equipment do they have in Jr. high, To help save peoples lives?
lawyer [7]

Vital signs monitors, Electronic Medical Records (EMR), and Medication Management Systems.

5 0
3 years ago
A device that converts analog signals into digital and vice versa for a computer to communicate over phone lines is called a ___
sweet [91]
The answer is modern
4 0
4 years ago
What did major networks do to combat audience erosion in the 1990s?
S_A_V [24]

Answer: I think is 3. They acquired cable channels. They acquired cable operators.

Explanation:

6 0
4 years ago
What is the difference between a programming language and natural (every-day) language?
Harlamova29_29 [7]
Natural languages are used for communication between people
6 0
3 years ago
Spotify uses data about musical preference to suggest new music to subscribers. This use of technology aids in spotify’s _______
sleet_krkn [62]

Spotify uses data about musical preference to suggest new music to subscribers. This use of technology aids in spotify’s <u>relationship marketing</u> efforts.

<u>Explanation:</u>

Relationship promoting is a system intended to encourage client reliability, collaboration and long haul commitment. It is intended to create solid associations with clients by furnishing them with data straightforwardly fit to their necessities and interests and by advancing open correspondence.

The standard mail advertising firm conveys transcribed birthday cards to customers and partners each year. This basic, individual touch assists customers with feeling like Direct Recruitment thinks about them as individuals as opposed to just shoppers.

5 0
3 years ago
Other questions:
  • You have been tracking your exercise routine, which involves running, lifting weights, yoga, and stretching. You want to see wha
    15·2 answers
  • In the 21st century organization we will see:
    10·1 answer
  • Type dig www.example A in order to get the IP address of www.example. What’s the TTL of the A record returned in the response? W
    9·1 answer
  • Difference between a print device and a printer
    13·1 answer
  • 3.24 LAB: Seasons
    13·1 answer
  • You run a small network for your business that has a single router connected to the Internet and a single switch. You keep sensi
    11·1 answer
  • Find the number of ideal integers within the given segment [low,high] inclusive. An ideal number is a positive integer that has
    9·1 answer
  • On which of the following pointing devices can you control the pointer by sliding your fingertip?
    11·1 answer
  • Nielsen purchases scanner data from retail transactions to track the sales of consumer packaged goods, gathered at the point of
    14·1 answer
  • To use the AutoCalculate area, select the range of cells containing the numbers for a calculation you want to verify and then pr
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!