Wednesday, January 6, 2016

Simple Calculator with Password in C (ver. 3.0.2)

ক্যালকুলেটরে নতুন সংযুক্তকরণঃ
১। পাসওয়ার্ড।
২। ৩ বারের অধিক পাসওয়ার্ড দিলে প্রোগ্রাম অফ।
৩। কিছু বাগ ফিক্সড করা হইসে। 

password: open//


Source: 

//a simple calculator by Habibur Rahman
//ver. 3.0.2
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>
main()
{
    char pass[7]="open//", getpass[7];
    int try, cmpr;
    printf("Enter Password to use this program.\nIf you enter wrong password more than 3 times,\nyou will be denied to access this software.\nSo be careful.\n");
    printf("--------------------------------------------\n\n");
    for(try=1; try<=3; try++){
        printf("try %d:\n", try);
        printf("       Enter your Password:");
        gets(getpass);
        cmpr=strcmp(getpass, pass);
        if(cmpr==0){
            printf("        >Succeed.\n");
            getch();
            break;
        }
        else if(try==3 && cmpr!=0){
            printf("        >Access Denied!\n");
            goto end;
        }
        else
        printf("        >Wrong Password!\a Try agin.\n\n");

    }
    system("cls");
    float num1, num2;
    char ch; //num1 for number 1, num2 for number 2, ch for character like +, -, *, /.
    printf("\tCalculator by Habib.\n");
    printf("\t--------------------\n");
    for(; ; )
    {
    scanf("%f %c %f", &num1, &ch, &num2);
    switch(ch)
    {
    case '+':
        num1=num1+num2;
        break;
    case '-':
        num1=num1-num2;
        break;
    case '*':
        num1=num1*num2;
        break;
    case '/':
        if(num2==0)
        {
            printf("Result is undefined.\a\n");
            goto last;

        }
        else
        num1=num1/num2;
        break;
    case '^':
        num1=pow(num1,num2);
        break;
    default:
        printf("Invalid!\a\n\n");
        break;
    }
    printf("=%f\a\n", num1);
    last:
        printf("--------------------------\n");
    }

    end:
        getch();
}

Output:




No comments:

Post a Comment

পোস্ট সম্পর্কে মতামত দিন