C Program#178 – To Develop Simple Four Function Calculator using if-elseif.

Program to Develop Simple Four Function Calculator using if-elseif.:

Program Logic :

  • First, Display a Menu System with Menu Options [+] – Addition , [-] – Subtraction , [/] – Division and [*] – Multiplication symbols for Input of choice in char data type variable.
  • Test input using test condition – if(ch==’+’ || ch==’-‘ || ch==’/’ || ch==’*’) for Validation of Input, if ok/TRUE, then proceed to take two values for desired operation.
  • Then, test individual conditions, using if-elseif statement as below-
  • if (ch==’+’) results TRUE then Add and Display results.
  • else if (ch==’-‘) results TRUE then Subtract and Display results.
  • else if (ch==’/’) results TRUE then use if(value2!=0) to test divide by zero error, if FALSE, then Divide and Display results.
  • At-last, else block then “Display Invalid Input”, message.
  • Still not understood ? See the proper working example in action below.




Full Well Commented, Self-Explanatory Example Program of the same given below.

Below Here are Six (6) different Outputs of the program.



Output of the Program (Run 1 ):

Output of the Program (Run 2 ):

Output of the Program (Run 3 ):

Output of the Program (Run 4 ):



Output of the Program (Run 5 ):

Output of the Program (Run 5 ):