Question

using Eclipse c++ Write a program that mimics a simple integer calculator using the switch statement....

using Eclipse c++ Write a program that mimics a simple integer calculator using the switch statement. The program should prompt for two integer numbers and the operation to be performed as input. It should then output the numbers, the operator, and the results as illustrated below. Use a for loop to prompt the user for input seven times as illustrated below. Assume that the operands will always be valid integers. For division,the program should also output the remainder and check if the denominator is zero (and output an appropriate message). If the operation is not recognized, an appropriate message should be output. Note that the program should wait for input of the ENTER key after displaying the message “Press ENTER to continue . . .”Test the program thoroughly!

Screen INPUT/OUTPUT-should be formatted as follows –(Class heading should be also displayed)

Enter two integers: 10 5

Enter operator: + , -, * , / : +

10 + 5 = 15

Press ENTER to continue...

Enter two integers: 25 35

Enter operator: + , -, * , / : -

25 -35 = -10

Press ENTER to continue...

Enter two integers: -1-1

Enter operator: + , -, * , / : *

-1 * -1 = 1

Press ENTER to continue...

Enter two integers: 9 6

Enter operator: + , -, * , / : /

9 / 6 = 1R3

Press ENTER to continue...

Enter two integers: 0 1

Enter operator: + , -, * , / : /

0 / 1 = 0R0

Press ENTER to continue...

Enter two integers: 1 0

Enter operator: + , -, * , / : /

1 / 0 = ERROR

Press ENTER to continue...

Enter two integers: 2 4

Enter operator: + , -, * , / : !

2 ! 4 = ILLEGAL

Press ENTER to continue...

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution(calc.cpp):

#include<iostream>
using namespace std;
int main()
{
   int a,b,result,rem,i;
   char op;
  
   for(i=1;i<=7;i++){
   cout<<"Enter two integers: ";
   cin>>a>>b;
   cout<<"Enter operator: + , -, * , / : ";
   cin>>op;
  
   switch(op)
   {
       case '+':result=a+b;break;
       case '-':result=a-b;break;  
       case '*':result=a*b;break;
       case '/':
       {
           if(b==0)
               cout<<a<<" / "<<b<<" = ERROR"<<endl;
           else
           {
               result=a/b;
               rem=a%b;
               cout<<a<<" / "<<b<<" = "<<result<<"R"<<rem<<endl;
           }
       }break;
       default:cout<<a<<" ! "<<b<<" = ILLEGAL"<<endl;  
   }
   if(op=='+' || op=='-' || op=='*')
       cout<<a<<" "<<op<<" "<<b<<" = "<<result<<endl;
  
   cout<<"Press ENTER to continue...";
   cin.ignore();
   cin.get();  
   }

   return 0;
}

Output:

Add a comment
Know the answer?
Add Answer to:
using Eclipse c++ Write a program that mimics a simple integer calculator using the switch statement....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CENGAGE MINDTAP Programming Exercise 4-8 Instructions Instructions Write a program that mimics a calculator. The program...

    CENGAGE MINDTAP Programming Exercise 4-8 Instructions Instructions Write a program that mimics a calculator. The program should take as input: 1. The first integer 2. The second integer 16 3. The operation to be 11 performed ( + . 12 13 ess 14 It should then output the 15 numbers, the operator, and the er 16 result. (For division, if the 17 c denominator is zero, output an 18 19 ( appropriate message. The 20 message should contain the word...

  • Write an assembler program that asks the user (as shown below) for two integers and a...

    Write an assembler program that asks the user (as shown below) for two integers and a single character representing the arithmetic operations: addition, subtraction, multiplication and integer division (displays both quotient and remainder). Perform the requested operation on the operands and display the result as specified below. Assume SIGNED NUMBERS. The program should not divide by 0! If the user attempts to divide by 0, display the error message: "Cannot divide by zero." If this error occurs, the program should...

  • A Simple Calculator Summary: Write a console program (character based) to do simple calculations (addition, subtraction,...

    A Simple Calculator Summary: Write a console program (character based) to do simple calculations (addition, subtraction, multiplication and division) of two numbers, using your understanding of Java. Description: You need to write a program that will display a menu when it is run. The menu gives five choices of operation: addition, subtraction, multiplication, division, and a last choice to exit the program. It then prompts the user to make a choice of the calculation they want to do. Once the...

  • 1) [5 pts] Build a simple calculator using switch statements which can perform the four operations...

    1) [5 pts] Build a simple calculator using switch statements which can perform the four operations +, -, *,/. Write a program that asks the user to enter two numbers/operands. Then prompt the user to enter the operator +,, ). Perform the corresponding operation and display the answer to user. The format Example of multiplication Microsoft Visual Studio Debug Console an operator (+, -, *, ): Enter two operands: 25.5 2.314 25.5 2.314597 2) [5 pts] Create a program to...

  • Write a Java program which allows the user to perform simple tasks on a calculator. A...

    Write a Java program which allows the user to perform simple tasks on a calculator. A series of methods allows the user to select an operation to perform and then enter operands. The first method displays a menu, giving the user the choice of typing in any one of the following: +, -, *, /, or % representing the usual arithmetic operators (Each operation should be done on numbers negative(-) to positive(+), positive(+) to negative(-), negative(-) to negative(-), and positive(+)...

  • Write a Java program to prompt for inputting an integer N, then enter N integers (a...

    Write a Java program to prompt for inputting an integer N, then enter N integers (a loop is needed), print the numbers user entered, and the amount of even and odd numbers (zero is even number). (1) Prompt for the user to input an integer and output the integer. (1 pts) Enter an integer: You entered: 5 (2) Prompt for the user to input N integers, output the numbers entered and the amount of even and odd numbers (9 pts)...

  • Write a c++ complete program to meet the specifications. The program should prompt the user for...

    Write a c++ complete program to meet the specifications. The program should prompt the user for a positive integer. The program should print a message whether the integer is even or odd. The looping should end when the user enters a negative number. The negative number will not be tested for even or odd. The program will print out a message of how many numbers were entered (not counting the negative number) and how many even and odd numbers were...

  • 1. Specification Write a C program to implement a simple calculator that accepts input in the...

    1. Specification Write a C program to implement a simple calculator that accepts input in the following format and displays the result of the computation: calc [operand_1] [operator] [operand_2] The operands operand_1 and operand_2 are non-negative integers. The operator is one of the following: addition (+), subtraction (-), multiplication (x), division (/) and modulo (%). Note: For the multiplication operator, use letter ‘x’. If you use the asterisk ‘*’, your program will not work properly 2. Implementation • The program...

  • use C++ please 1. Vowels and Consonants Write a program that asks the user to input...

    use C++ please 1. Vowels and Consonants Write a program that asks the user to input three different integers. Write a function called numberStyle for this program that will accept each integer (one at a time) and return the following . If the integer is even, return 1 . If the integer is odd, return -1 . If the integer is zero, return O In main, after calling the function output the appropriate message describing the integers ing the function...

  • Creating a Calculator Program

    Design a calculator program that will add, subtract, multiply, or divide two numbers input by a user.Your program should contain the following:-The main menu of your program is to continue to prompt the user for an arithmetic choice until the user enters a sentinel value to quit the calculatorprogram.-When the user chooses an arithmetic operation (i.e. addition) the operation is to continue to be performed (i.e. prompting the user for each number, displayingthe result, prompting the user to add two...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT