my code stock.com

Jefferson Jose Torres Munoz

An express calculator
by Jefferson Jose Torres Munoz

This calculator can do the four basic operations. It needs to be added more functions for the future, like roots and trigonometric and exponential functions.

Snippet options

Download: Download snippet as an-express-calculator.c.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

#include <stdio.h>
#include <stdlib.h>

/*      An express calculator       */

int main()
{
    char letter;
    float num1, num2;
    printf("What operation do you want to do?\n\tA)Addition\n\tB)Substraction\n\tC)Multiplication\n\tD)Division\n\n");
    scanf("%c", &letter);
    printf("\nPlease enter a number: ");
    scanf("%f", &num1);
    printf("Please enter a number: ");
    scanf("%f", &num2);
    if (letter == 'A' || letter == 'a')
            printf("The sum of %.2f and %.2f is %.2f", num1, num2, num1 + num2);
    else if (letter == 'B' || letter == 'b')
            printf("The difference or substraction of %.2f and %.2f is %.2f", num1, num2, num1 - num2);
 else if (letter == 'C' || letter == 'c')
            printf("The multiplication of %.2f and %.2f is %.2f", num1, num2, num1 * num2);
 else if (letter == 'D' || letter == 'd')
            printf("The division of %.2f and %.2f is %.2f", num1, num2, num1 / num2);
 else
        printf("You entered an invalid character");

   return 0;
}

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.