Calculator in C

By: Emiley J  

This is a simple calculator written in C. To use this calculator, just type the number, followed by the operand and then by another number. The application will then display the result. After the result is displayed, the program goes into the loop which asks if they want to do another calculation. If y is pressed, another calculation can be carried out.

#include 

int main()
{
  double number1 = 1.0;
  double number2 = 2.0;
  char operation = '+';
  char answer = 0;



  switch(operation)
  {
    case '+':
      printf("= %lf\n", number1 + number2);
      break;

    case '-':
      printf("= %lf\n", number1 - number2);
      break;

    case '*':
      printf("= %lf\n", number1 * number2);
      break;

    case '/':
      if(number2 == 0)
        printf("\n\n\aDivision by zero error!\n");
      else
        printf("= %lf\n", number1 / number2);
      break;

    case '%':
      if((long)number2 == 0)
        printf("\n\n\aDivision by zero error!\n");
      else
        printf("= %ld\n", (long)number1 % (long)number2);
      break;

    default:
      printf("\n\n\aIllegal operation!\n");
  }
}



Archived Comments

1. this is very bad program because this is not run and very very mistake in this program .this is not
View Tutorial          By: danish at 2016-07-07 05:34:36

2. Thanks for sharing. But I have made my own simple calculator. You can check it out here at http://ww
View Tutorial          By: RIo Eduardo at 2013-02-18 02:39:08

3. the 2 not required lines
1) #include
2) char answer = 0

Add a line w

View Tutorial          By: saurabh at 2012-02-20 06:33:57

4. Its not working ave made a few adjustments to it though and it okay now
View Tutorial          By: amg at 2011-11-04 13:48:09

5. hi ,c language use for business man,wast for poor peoples (gradates) , so your use for any langu
View Tutorial          By: p rambabu rddy at 2011-10-05 08:58:34

6. The program doesn't work as how it is described.
View Tutorial          By: Gurucharan at 2011-02-03 09:21:18

7. Good work. Keep it up.
View Tutorial          By: pickatutorial at 2010-10-09 09:19:50


Most Viewed Articles (in C )

Latest Articles (in C)

Comment on this tutorial