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
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
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 7 images
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning