Write a small "calculator" using a switch statement. It will work as follows: it asks the user for an operation to perform, that will be made of two numbers between an operator (a single character). The program will then display the result of this operation. Supported operations are the four basic ones: addition ('+'), subtraction ('-'), multiplication (*"), division ('/'). Other kinds of input should produce an error. Sample output1: Enter an operation: 3.4 + 7.1 10.5 Sample output2: Enter an operation: 7 - 3 4 Sample output3: Enter an operation: 3 * 1.4 4.2 Sample output4: Enter an operation: 10 / 3 3.33333 Sample output5: Enter an operation: 14 % 3 ERROR

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 30PE
icon
Related questions
Question
Write a small "calculator" using a switch statement. It will work as follows: it asks the user for an operation to perform, that will be made of two numbers between an
operator (a single character). The program will then display the result of this operation. Supported operations are the four basic ones: addition ('+'), subtraction ('-'),
multiplication (*'), division ('/'). Other kinds of input should produce an error.
Sample output1:
Enter an operation: 3.4 + 7.1
10.5
Sample output2:
Enter an operation: 7 -
3
4
Sample output3:
Enter an operation: 3 *
1.4
4.2
Sample output4:
Enter an operation: 10 / 3
3.33333
Sample output5:
Enter an operation: 14 % 3
ERROR
Transcribed Image Text:Write a small "calculator" using a switch statement. It will work as follows: it asks the user for an operation to perform, that will be made of two numbers between an operator (a single character). The program will then display the result of this operation. Supported operations are the four basic ones: addition ('+'), subtraction ('-'), multiplication (*'), division ('/'). Other kinds of input should produce an error. Sample output1: Enter an operation: 3.4 + 7.1 10.5 Sample output2: Enter an operation: 7 - 3 4 Sample output3: Enter an operation: 3 * 1.4 4.2 Sample output4: Enter an operation: 10 / 3 3.33333 Sample output5: Enter an operation: 14 % 3 ERROR
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 7 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning