0

我有一个读取 EMSO 的程序(一个告诉你出生日期、州、性别和其他一些东西的数字)。它是生成的,它是一个 13 位数字。最后一个是控件,前两个是日,后两个是月,后三个是年。我希望程序通过 EMSO 和当前计算机日期计算出您的年龄。这是我到目前为止所写的:

#include <stdio.h>
#include <windows.h>

int main (void) 
{
unsigned long long int  emso;
int kontrola;
int a,b,c,d,e,f,g,h,i,j,k,l;
int x,y;
int kraj;

system("cls");  

printf("Enter your EMSO: ");
while(scanf("%lld",&emso)!=1)fflush(stdin);



    while(emso!=-1){

    kontrola=emso%10;
    emso/=10;
    l=emso%10;
    emso/=10;
    k=emso%10;
    emso/=10;
    j=emso%10;
    emso/=10;
    i=emso%10;
    emso/=10;
    h=emso%10;
    emso/=10;
    g=emso%10;
    emso/=10;
    f=emso%10;
    emso/=10;
    e=emso%10;
    emso/=10;
    d=emso%10;
    emso/=10;
    c=emso%10;
    emso/=10;
    b=emso%10;
    emso/=10;
    a=emso%10;

    x= (7*a+ 6*b+ 5*c+ 4*d+ 3*e+ 2*f+ 7*g+ 6*h+ 5*i+ 4*j+ 3*k+ 2*l);
    x=x%11;

    if (x!=0){
        x=11-x;     
    }


    kraj=h*10+i;

    if (x==kontrola){
        printf("\n\nEMSO is legitimate!\n");
        if(j==0){
            printf("\nPerson is MALE\n");
        }
            else if (j==5){
                printf("\nPerson in FEMALE\n");
            }


        if (e==9){
            y=1;
        }

        else if (e==0){
            y=2;
        }

        printf("\nDate of birth: %d%d.%d    %d.%d%d%d%d.\n",a,b,c,d,y,e,f,g);   

        if (kraj >=00 && kraj <10){
            printf("\nPerson was born abroad!\n");
        }

        if (kraj>=10 && kraj < 20){
            printf("\nPerson was born in BiH.\n");
        }

        if(kraj >=20 && kraj < 30){
            printf("\nPerson was born in Montenegro.\n");
        }

        if (kraj >= 30 && kraj < 40){
            printf("\nPerson was born in Croatia.\n");
            if (kraj == 33){
                printf("\tPerson was born in Zagreb.\n");
            }
        }

        if (kraj >=40 && kraj < 50){
            printf("\nPerson was born in Macedoniji.\n");
        }

        if (kraj >= 50 && kraj < 60){
            printf("\nPerson was born in Slovenia.\n");
        }

        if (kraj >=70 && kraj < 80){
            printf("\nPerson was born in Srbia.\n");
            if (kraj == 71){
                printf("\tPerson was born in Beogerad.\n");
                }
        }

        if (kraj >=80 && kraj < 90){
            printf("\nPerson was born in Vojvodina.\n");
            if(kraj == 80){
                printf("\tPerson was born in Novi Sad.\n");
                }
        }

        if (kraj >=90 && kraj < 100){
            printf("\nPerson was born in Kosovo.\n");
        }
    }

    if (x!=kontrola){
        printf("\nEMSO is NOT legitimate!\n");
    }

    printf("\n");
    system("pause");
    system("cls");  


    printf("Enter your EMSO: ");
    while(scanf("%lld",&emso)!=1)fflush(stdin);
}


return 0;

}

在所有这些混乱中,a&b代表日,代表cd月,代表efg年。

此外, fflush 的东西不能正常工作。它破坏了出生印记。

为了更好地理解,这是我的 emso:0701996500037。这是正常情况下出现的结果:EMSO 是合法的!

人是男性

出生日期:1996 年 1 月 7 日。

人出生在斯洛文尼亚。

我很高兴。如果我写这个:0701996500037ž,没问题,同样的输出。但是如果我输入z0701996500037,没有反应,就像没有输入一样。一个如果我写0701u996500037,验证是可以的,但其他都是错误的。地点和出生是错误的

4

2 回答 2

0

time返回自 Epoch 以来的秒数。mktime返回自 Epoch 以来的秒数作为它的struct tm *参数。因此:

struct tm date = { /* fill tm_year, tm_mon, etc. */ };
double seconds_since_date = difftime(time(0), mktime(&date));

会给你自日期以来经过的秒数。(这不考虑时区。)

于 2012-08-20T21:53:34.903 回答
-1

请检查下面的链接,这可能对你有帮助

http://www.cplusplus.com/reference/clibrary/ctime/time/

于 2012-08-20T22:09:25.700 回答