Choď na obsah Choď na menu

Calculator, v2.0 - source code

22. 7. 2018

#include <stdio.h>
main()
{
    int first,second,operation,equals,loop=1;

    system("title Calculator");
    printf("https://www.benik-software.estranky.sk\n");
    printf("--------------------------------------\n");
    while(loop==1)
    {
        printf("Enter first number: ");
        scanf("%d",&first);
        printf("Enter second number: ");
        scanf("%d",&second);
        printf("Enter + (NumPad 1),- (NumPad 2),* (NumPad 3) or / (NumPad 4): ");
        scanf("%d",&operation);
        if(operation==1)
        {
            equals=first+second;
            printf("%d+%d=%d",first,second,equals);
        }
        if(operation==2)
        {
            equals=first-second;
            printf("%d-%d=%d",first,second,equals);
        }
        if(operation==3)
        {
            equals=first*second;
            printf("%d*%d=%d",first,second,equals);
        }
        if(operation==4)
        {
            equals=first/second;
            printf("%d/%d=%d",first,second,equals);
        }
        if(operation!=1&&operation!=2&&operation!=3&&operation!=4)
            printf("Error.");
        printf("\n");
        system("pause");
        system("cls");
        }
}