Question

In: Computer Science

Integer value calculator: Write a program using C++ that acts as a calculator. The program should...

Integer value calculator: Write a program using C++ that acts as a calculator. The program should ask the user for two numbers and an operator. Then the program must print the result using the two input values and the operator.

Prompts and input requirements. Ask the user for two integer values and a value that indicates the operation. Likely you will want to choose the normal operators: + - * / %.

Output Requirements: Make your output easy to understand, both in the prompts and when printing the result.

Input Validation. The program should validate all input from the user and print an error message if the input is not valid. The integer values must be between -30,000 and + 30,000 and the operators must be one of these: + - * / %. If the input is not valid, the program should exit without printing a result.

Solutions

Expert Solution

Plss give like if u like my answer and any doubt free to ask.

#include<iostream>
using namespace std;

int main()
{
    int num1,num2; //Take two integer variable for storing two numbers.
    char op; //Take a character variable for storing operator.
    cout<<"Enter two numbers:";
    cin>>num1>>num2; //Taking user input for two number.
    cout<<"Enter Operator:";
    cin>>op;//Taking user input for operator.
    if(num1=>-30000 && num1<=30000 && num2=>-30000 && num2<=30000 && op=='-'|| op=='+'||op=='*' ||op=='/')//inside if taking conditions as you given in question
    {
        switch(op)//use switch case for doing operation.
        {

            case '+':
                cout<<"Addition of these two numbers:"<<num1+num2;
                break;
            case '-':
                cout<<"Subtraction of these two numbers:"<<num1-num2;
                break;
            case '*':
                cout<<"Multiplication of these two numbers:"<<num1*num2;
                break;
            case '/':
                cout<<"Division of these two numbers:"<<num1/num2; //if u want division in points like 0.764 then u have to take num1 and num2 as float.
                break;
            default:
                break;
        }

    }
    else
    {
        cout<<"The integer values must between -30000 and +30000and the operator must be one of these:+-/*."; //For error.
    }

    return 0;
}


Related Solutions

TASK: Using stack functions, write a program in C++ language that acts as a simple calculator,...
TASK: Using stack functions, write a program in C++ language that acts as a simple calculator, reading an infix algebraic expression with numbers and simple operations: +, -, *, / , (, and ). The program converts an infix expression into an equivalent postfix expression, and then evaluates the postfix expression, and then prints the result if input expression is correct otherwise prints error messages. Your program must interact with the user until the user quits.    REQUIREMENTS: - Your...
Write a C++ program that accepts a single integer value entered by user. If the value...
Write a C++ program that accepts a single integer value entered by user. If the value entered is less than one the program prints nothing. If the user enters a positive integer n. The program prints n x n box drawn with * characters. If the user enters 1 , for example the program prints *. If the user enter a 2, it prints ** ** that is , a 2x2 box of * symbols.
Write a program in C or in Java, that takes an integer value N from the...
Write a program in C or in Java, that takes an integer value N from the command line, generates N random points in the unit square, and computes the distance separating the closest pair of points. A unit square is a square with sides of length 1, at points (0, 0), (0, 1), (1, 0), and (1, 1). If you wish to avoid the command-line processing, you can just assume you will generate a fixed number of points, say between...
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value....
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value. The program should then output a message saying whether the number is positive, negative, or zero.
Write a program that acts as a basic calculator Assume the starting result is 0 Ask...
Write a program that acts as a basic calculator Assume the starting result is 0 Ask the user for the operation to be performed 0 – Exit 1 – Add 2 – Subtract 3 – Multiply 4 – Divide (Assume input will not be 0) Keep on performing the operation and showing the result until the user inputs the ‘0’ (exit) operation. You need to have everything written as functions E.g. - You should only have the options listed once...
Write a C++ program which prompts the user to enter an integer value, stores it into...
Write a C++ program which prompts the user to enter an integer value, stores it into a variable called ‘num’, evaluates the following expressions and displays results on screen. num+5, num-3, (num+3) – 2, ((num+5)*2 / (num+3)) For performing addition and subtraction, you are allowed to use ONLY the increment and decrement operators (both prefixing and postfixing are allowed). You must remember that using increment/decrement operators changes the original value of a number. Indent your code and include comments for...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value between 1 and 3 (where 1=paper, 2=scissor, and 3=rock). This input should be passed into a string function called player_RPS(), and returns a string value indicating the selection of paper, scissors, or rock (as mentioned above). Next, the returned string value, along with a generated input from the computer, should be passed into a void function called RPS_comparison(), and determines whether the user’s input...
Write a simple Calculator program using Scheme programming language. It should be able to do following...
Write a simple Calculator program using Scheme programming language. It should be able to do following operations: "+", "-", " * *, "/". the format when using the calculator function should be (calculator(operand1 operation operand2)) -> (calculator(2 + 5)) should give the output of 7.
USING C# 1. Write a program that takes outputs a string, an integer and a floating-point...
USING C# 1. Write a program that takes outputs a string, an integer and a floating-point number separated by commas. Sample output: Bob Marley, 20, 5.2 2. 2. Write a program that asks the user for a string of letters of any size (no spaces), and finally a special character (values 33 to 47 in the Ascii table, or ‘!’ to ‘/’). Generate a random number of any size, integer or floating point, and combine those three pieces of information...
2) Write an elementary calculator in which the main program reads an integer input, an operation...
2) Write an elementary calculator in which the main program reads an integer input, an operation (+,-,*,/), and another integer input. It then passes this information to a function (calc) to perform this operation. This function (calc) returns the result using switch statements for operation decision. The program stops when the user inputs 0 for both integer inputs in the main program.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT