Support Forums
Calculator in C - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Programming with C++ (https://www.supportforums.net/forumdisplay.php?fid=20)
+---- Thread: Calculator in C (/showthread.php?tid=3305)



Calculator in C - Liberty - 12-03-2009

Hi SF,

I made a little calculator, like Xenocide but in C and I made it like 3 weeks ago but here it is:

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

int main()
{
    int equation, nombre1, nombre2, resultat, calculator=1;
    printf("Calculator in C by So.Liberty\n\n");
    while(calculator){
    printf("Which operation would you like to do?\n\n");
    printf("1. Addition\n");
    printf("2. Substraction\n");
    printf("3. Multiplication\n");
    printf("4. Division\n");
    scanf("%d", &equation);
    if(equation ==1)
    {
        printf("\n\nAddition\n\n");
        printf("Enter the first number:\n");
        scanf("%d", &nombre1);
        printf("Enter the second one:\n");
        scanf("%d", &nombre2);
        resultat=nombre1+nombre2;
        printf("There you go: %d", resultat);
        printf("\n\nWould you like to do another operation?(1 for yes / 0 for no)\n\n");
        scanf("%d",&calculator);
    }
    else if(equation==2)
    {
        printf("\n\nSubstraction\n\n");
       printf("Enter the first number:\n");
        scanf("%d", &nombre1);
        printf("Enter the second one:\n");
        scanf("%d", &nombre2);
        resultat=nombre1-nombre2;
        printf("There you go: %d", resultat);
        printf("\n\nWould you like to do another operation?(1 for yes / 0 for no)\n\n");
        scanf("%d",&calculator);
    }
    else if(equation==3)
    {
        printf("\n\nMultiplication\n\n");
        printf("Enter the first number:\n");
        scanf("%d", &nombre1);
        printf("Enter the second one :\n");
        scanf("%d", &nombre2);
        resultat=nombre1*nombre2;
        printf("There you go: %d", resultat);
        printf("\n\nWould you like to do another operation?(1 for yes / 0 for no)\n\n");
        scanf("%d",&calculator);
    }
    else if(equation==4)
    {
        printf("\n\nDivision\n\n");
        printf("Enter the first number:\n");
        scanf("%d", &nombre1);
        printf("Enter the second one:\n");
        scanf("%d", &nombre2);
        resultat=nombre1/nombre2;
        printf("There you go: %d", resultat);
        printf("\n\nWould you like to do another operation?(1 for yes / 0 for no)\n\n");
        scanf("%d",&calculator);
    }
    else
    {
        printf("Go away if you don't like mathematics");
    }}
    return 0;
}



RE: Calculator in C - bTwornR - 12-10-2009

For what is
scanf?


RE: Calculator in C - MrD. - 12-10-2009

(12-10-2009, 11:20 AM)bTwornR Wrote: For what is
scanf?

http://lmgtfy.com/?q=scanf


RE: Calculator in C - Brainless Control - 12-10-2009

(12-10-2009, 11:20 AM)bTwornR Wrote: For what is
scanf?

If you get into C programming you will understand what scanf is and everything.


RE: Calculator in C - Sagittarius - 12-10-2009

if you can?....plz modefy to C++ coding