Question

5. Write a program in C++ that will perform the operation of a simple CALCULATOR. But its output will be as shown in the outp with the correct answer please
0 0
Add a comment Improve this question Transcribed image text
Answer #1
 #include <iostream> using namespace std; int main() { char option,sign;   int num1,num2; float result; // Loop forever (or till we hit the break statement)      do      {        result = 0.0;   cout << "Do you want to start the Calculator(Y/y : N/n)? :";      cin >> option;    if(option == 'n' || option == 'N')      {       cout<<"Good Bye...... !"; break;          } cout << "Welcome to the calculator......\n\n"; cout << "Please enter an operation (+, -, *, /)? : "; cin >> sign; if (sign != '+' && sign != '-' && sign != '*' && sign != '/')            {                       cout << "Unknown operator " << sign << '\n';                  continue;               }               else            {                cout << "Please enter a two numbers :"; cin >> num1>>num2;                   if (sign == '+')                        {                        result = num1+num2;                    }                       else if(sign == '-')                    {                               result = num1-num2;                     }                       else if(sign == '*')                    {                               result = num1*num2;                     }                       else if(sign == '/')                    {                        if(num2 == 0)                   {                              cout<<"Cannot divide by 0\n";                      continue;                       }                              result = (float)num1/ (float)num2;                      }               }               cout<<"\n\nYou have choosen the operator : "<<sign;                 printf("\nYour calculation result is : %f \n\n",result);                }while (1);      return (0); } 
Add a comment
Know the answer?
Add Answer to:
with the correct answer please 5. Write a program in C++ that will perform the operation...
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
  • Please solve in java Write a program that serves as a simple calculator. The program should...

    Please solve in java Write a program that serves as a simple calculator. The program should ask the user for a number, an operator, and then a second number. The operator should be either '+', '-', 'x', or '/'. The program should then report the answer to the problem. Use a switch statement, not an if statement. You'll need to read the operator as a String and compare it using Strings, as you did in 4.1. Turn in your source...

  • Please write below code in C++ using Visual Studio. Write program that uses a class template...

    Please write below code in C++ using Visual Studio. Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) • Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 • Hint: Use vectors and vector functions to store the set of items 2. Get the number of items in the...

  • 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...

  • JAVA Write a program which will receive three pieces of data from the user: two floating...

    JAVA Write a program which will receive three pieces of data from the user: two floating point numbers, and a single character +, -, *, or /. Perform input validation on the character. Your code then will send these three pieces of data to a method which will calculate and output the results based on the user's entries. For example, if the user entered: "12.1, 23.2, +" the output would be "12.1 + 23.2 = 35.3." STRONG HINT: in a...

  • PLease IN C not in C++ or JAVA, Lab3. Write a computer program in C which...

    PLease IN C not in C++ or JAVA, Lab3. Write a computer program in C which will simulate a calculator. Your calculator needs to support the five basic operations (addition, subtraction, multiplication, division and modulus) plus primality testing (natural number is prime if it has no non-trivial divisors). : Rewrite your lab 3 calculator program using functions. Each mathematical operation in the menu should be represented by a separate function. In addition to all operations your calculator had to support...

  • In C language, please use at least one user defined function, and show data validity check...

    In C language, please use at least one user defined function, and show data validity check for != integers 3) Write a program to find whether a given number is a Palindrome number (number that is same when you read from forward or backward). You need to take a long integer number from user as input and verify whether it's a number and positive or not. If the input is not valid (e.g., string or float) or positive, then notify...

  • This program will implement a simple guessing game... Write a program that will generate a random...

    This program will implement a simple guessing game... Write a program that will generate a random number between 1 and 50 and then have the user guess the number. The program should tell the user whether they have guessed too high or too low and allow them to continue to guess until they get the number or enter a 0 to quit. When they guess the number it should tell them how many guesses it took. At the end, the...

  • Write a program in C++ that uses a class template to create a set of items....

    Write a program in C++ that uses a class template to create a set of items. . . The Problem Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 Hint: Use vectors and vector functions to store the set of...

  • please code in basic c++ program Write a program that uses the following formula: n (ax...

    please code in basic c++ program Write a program that uses the following formula: n (ax - ib) i=1 Your program will prompt the user for the number of iterations for the calculation. input values for n, x, a, b, and c. n must be a positive integer, but x, a, b, and c can be any real numbers. Then it will perform the calculation and output the result. Then, it will ask the user if they would like to...

  • How to solve this Problem in C++ . The Problem Write program that uses a class...

    How to solve this Problem in C++ . The Problem Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 Hint: Use vectors and vector functions to store the set of items 2. Get the number of items in the set...

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
ADVERTISEMENT