(I'm very confused with this, kinda not understanding, any chance you can help answer and explain. This is for devc++, i use version 5.11)   Implement the Calculator code we covered on Oct 13th using switch

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 28SA
icon
Related questions
Question

 

(I'm very confused with this, kinda not understanding, any chance you can help answer and explain. This is for devc++, i use version 5.11)

 

Implement the Calculator code we covered on Oct 13th using switch

 

/* Implement a calculator
take the input for a character
if character is "+", then it's going to take the input of two numbers and show the sum
if character is "-", then it's going to take the input of two numbers and show the minus result
if character is "*", then it's going to take the input of two numbers and show the product
if character is "/", then it's going to take the input of two numbers and show the divide result
if character is "%", then it's going to take the input of two numbers and show the modulus result
if character is "^", then it's going to take the input of two numbers and show the number1^number2

*/

#include <iostream>
#include <cmath>
using namespace std;
int main(){
char operation;
int number1, number2;
cout << "Enter +, -, *, /, %, ^";
cin >> operation;
if ( operation == '+' ){
//take the input of two numbers and display the sum
cout << "Enter two numbers";
cin >> number1 >> number2;
cout << "Sum is = "<< (number1+number2)<<endl;
}
else if ( operation == '-' ){
//take the input of two numbers and display the minus result
cout << "Enter two numbers";
cin >> number1 >> number2;
cout << "Number 2 subtracted from number 1 is = "<< (number1-number2)<<endl;
}
else if ( operation == '*' ){
//take the input of two numbers and display the sum
cout << "Enter two numbers";
cin >> number1 >> number2;
cout << "Product is = "<< (number1*number2)<<endl;
}
else if ( operation == '/' ){
//take the input of two numbers and display the divide result
cout << "Enter two numbers";
cin >> number1 >> number2;
cout << "Number1 divided by number 2 is = "<< (number1/number2)<<endl;
}
else if ( operation == '%' ){
//take the input of two numbers and display the modulus
cout << "Enter two numbers";
cin >> number1 >> number2;
cout << "Modulus is = "<< (number1%number2)<<endl;
}
else if ( operation == '^' ){
//take the input of two numbers and display the pow
cout << "Enter two numbers";
cin >> number1 >> number2;
cout << "Number1 raised to number2 is = "<< (pow(number1,number2))<<endl;
}
else
cout << "Invalid operator";



}

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Print statement
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
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