Question

write a C program that emulates you with the calculator which can operate with the four...

write a C program that emulates you with the calculator which can operate with the four operations ( + - / * ) , the program should keep running and asks the user to end or continue use functions to create the calculator part

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

The following c program emulates the user with calculator.

#include<stdio.h>
typedef long long ll;
ll add(ll x,ll y)
{
return x+y;
}
ll sub(ll x,ll y)
{
return x-y;
}
ll mul(ll x,ll y)
{
return x*y;
}
double div(ll x,ll y)
{
return (1.0*x)/y;
}
int main()
{
ll a,b;
char ch;
while(1)
{
scanf(" %c",&ch);
switch(ch)
{
case '+':scanf("%lld%lld",&a,&b);
printf("%lld\n",add(a,b));
break;
case '-':scanf("%lld%lld",&a,&b);
printf("%lld\n",sub(a,b));
break;
case '*':scanf("%lld%lld",&a,&b);
printf("%lld\n",mul(a,b));
break;
case '/':scanf("%lld%lld",&a,&b);
printf("%0.6lf\n",div(a,b));
break;
default:exit(0);
}
}
}

Here is the sample input and corresponding output:

CUsersPanical Documents HomeworkLib.exe 45 34 2285714 AA F ING 01:13 AMIf you find this helpful please upvote:

Add a comment
Know the answer?
Add Answer to:
write a C program that emulates you with the calculator which can operate with the four...
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
  • Write a C++ Program that simulates a basic calculator using functions which performs the operations of...

    Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for list of operations that can be calculated and get the input from user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations must be...

  • Write a C++ Program that simulates a basic calculator using functions which performs the operations of...

    Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for the list of operations that can be calculated and get the input from the user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations...

  • You want to write a converter program which will let user convert distance and weight from SI to ...

    Use functions to complete this C + + program You want to write a converter program which will let user convert distance and weight from SI to the USCS system and vice versa The formulae are as follows: 1. Distance in miles- distance in kilometers x 1.60 2. Weight in kilograms weight in pounds x 2.20 The program would let user input the number that they want to convert and then choose the units to and from which they want...

  • Write a Program that has a menu with a  layout below, that asks the user if they...

    Write a Program that has a menu with a  layout below, that asks the user if they want to: 1. Converts from feet and inches to meter and centimeters 2. Converts from meter and centimeters to feet and inches 3. Quit the program The program should continue as long as the user asks it to. The program will use a switch statement for the menu option selection. Either a do loo or a do-while loop can be used for the overall...

  • 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 calculator program using JavaScript in HTML in the same HTML file. (There will only...

    Write a calculator program using JavaScript in HTML in the same HTML file. (There will only be 1 HTML file containing everything that you use for this program.) *************JavaScript Functions should be written in the HTML <head> .............. </head> tag, **************** (Please be mindful of the formatting of the text of your program. Meaning that do not copy paste everything in a single line. Add clear comments for a better understanding of your program) as follows Assignment: create a form...

  • Languge C Code Write a program that acts as an integer calculator that supports a single...

    Languge C Code Write a program that acts as an integer calculator that supports a single arithmetic operation at a time. The user should enter the calculation on a single line. The program should continuously accept new inputs before until the user submits a blank line (return). The program should support all of the following operations: +, -, *, /, % (modulo). It should not be necessary to use the math.h library. Your program should not produce any output except...

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

  • Q2- Write a C program that work as a calculator for the 4 main operations (...

    Q2- Write a C program that work as a calculator for the 4 main operations ( + * / - ), an error message should be displayed when the user attempts to divide by zero. The user input should be in this form: Number operation number, ex: 2-3‏

  • CE – Return and Overload in C++ You are going to create a rudimentary calculator. The...

    CE – Return and Overload in C++ You are going to create a rudimentary calculator. The program should call a function to display a menu of three options: 1 – Integer Math 2 – Double Math 3 – Exit Program The program must test that the user enters in a valid menu option. If they do not, the program must display an error message and allow the user to reenter the selection. Once valid, the function must return the option...

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