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
Select the correct answer.
Umnica [9.8K]

Answer:

OB. by zooming in on them

hope it helps

7 0
3 years ago
Ryan has made a presentation of ten slides, which he wants to display in sequence after a specific time interval. Which element
erastovalidia [21]
Open Slide how Tab Then Set up Group and then  Select Rehearse set each slide time according to your requirement
6 0
3 years ago
Read 2 more answers
Create your code from the story using code blocks.You must include at least one of each of the following blocks. You can draw or
Mazyrski [523]

Answer:

Como puedo hacerlo.

Explanation:

Me enseñas como hacerlo

6 0
3 years ago
Read 2 more answers
What two devices in a computer should be considered "black boxes," and should never be opened due to risks involving charged cap
NNADVOKAT [17]

The two devices in a computer that should be considered "black boxes," and should never be opened due to risks involving charged capacitors are MONITOR and POWER SUPPLY.

Explanation:

  • Physical contact or close proximity to the open power supply caused a discharge from the capacitor that resulted in an electric shock. Capacitors can discharge current even when not energized because they hold a charge for some time after the power is turned off.
  • To do harm to your body, the voltage across the capacitor's terminals must be high enough to cause a harmful effect on you. There are no hard rules for at what voltage things become harmful, but a common 'rule of thumb' is that DC up to 48 Volt is considered low voltage. So a capacitor charged to a voltage below 48 V is fairly safe.
  • A charged capacitor can be very dangerous, so it's important that you avoid coming into contact with the terminals at all times.
3 0
3 years ago
After a CPU decodes an instruction, what is the next step in the execution cycle?
Nat2105 [25]

Answer: E) The CPU executes the instruction by performing ALU operations.

Explanation: The execution cycle is of three stages namely; fetch, decode and execute. These are the functions that the CPU carries out from the time of boot-up up until it's shut down.

At the fetch stage, the computer retrieves program instructions from its memory register, at the decode stage; the decoders interprets the instructions from the instructions register and then the next stage will be the executions, at this stage; the interpreted instructions are then passed to relevant function units of the CPU to carry out the required instructions.

E.g mathematical and logic functions are passed on the ARITHMETIC AND LOGIC UNIT(ALU) to perform.

8 0
3 years ago
Other questions:
  • You want to arrange 6 of your favorite CD's along a shelf. How many different ways can you arrange the CD's assuming that the or
    15·1 answer
  • a problem exists when the current condition differs from a desired condition. This idea defines which step in problem-solving?
    13·2 answers
  • What is the most happy job work? that can earn $1000 per day at homes? show company website links
    5·1 answer
  • A computer has the following parameters Operation Frequency Cycles Arithmetic/Logical instructions 65% 1 Register load operation
    11·1 answer
  • Which of the following are results of technological advancements and increased automation?
    6·2 answers
  • How does having weak security on your browser represent the weakest link in a network
    8·1 answer
  • Which of the following is not a natural resource
    11·2 answers
  • Which are the following 4 things something must be able to do in order to be a computer? *
    9·1 answer
  • Terri brought a magazine for $5, and 2 bottles of nail polish. Write an expression to represent the total amount she spent. Then
    5·1 answer
  • Write an algorithm to print the odd number from 100 to 1​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!