Active1 year, 5 months ago
How to Write a Calculator Program in C. This article will explain the process of. Used in this article will be C++ so make sure the language setting is set to C++. How can I make a calculator using C programming? However I made a C program for the Calculator which can calculate Addition, Subtraction, Multiplication, Division, finding Square,Cube, Percentage of the numbers. Making a simple calculator using c programming language is very simple.
I want to make a simple C calculator only with 'IF' and 'IF ELSE' conditions and it don't let me choose an operator ('+, -, * or /'), just appear my last if condition.
DimitriDimitri
migrated from superuser.comJan 23 '15 at 23:17
This question came from our site for computer enthusiasts and power users.
![Calculator Program In C Language Calculator Program In C Language](http://videoparticular.com/pictures/e05DFjuY2ig.gif)
4 Answers
I avoid
Weather VaneWeather Vanescanf()
and its cousins. Here is a version of your calculator that uses fgets()
for the input. It also uses double
for the operands.28.2k66 gold badges2222 silver badges4040 bronze badges
This
should change to
so you let
Iharob Al AsimiIharob Al Asimiscanf()
ignore the 'n'
left by previous scanf()
s.49.1k55 gold badges4545 silver badges8383 bronze badges
I was also trying to apply my knowladage of C in a simple calculator and came across you question. In order to respect your if...else request I've come up with this solution. I hope this helps.
Dr3amcast3rDr3amcast3r
Mb.MustaqeemMb.Mustaqeem
Not the answer you're looking for? Browse other questions tagged ccalculator or ask your own question.
Calculators are widely used device nowadays. It makes calculations easier and faster. Calculators are used to everyone in daily life. A simple calculator can be made using a C++ program which is able to add, subtract, multiply and divide, two operands entered by the user. The switch and break statement is used to create a calculator.
Program:
// switch statement using namespace std; // Main program { float num1, num2; // It allows user to enter operator i.e. +, -, *, / cin >> num1 >> num2; // Switch statement begins case '+' : break ; // If user enter - cout << num1 - num2; case '*' : break ; // If user enter / cout << num1 / num2; // error message will display cout << 'Error! operator is not correct' ; } // switch statement ends return 0; |
Output:
- Click on the run ide button, another tab will be open with web address
“https://ide.geeksforgeeks.org/index.php” - Put the input in the input box
- Enter the arithmetic operator (i.e.: either +, -, * or /) then, enter two operands on which need to perform the calculation
- Click on the run button
- Then output box will appear with output
Recommended Posts:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to [email protected]. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the 'Improve Article' button below.