gpt4 book ai didi

在C中以日期形式组合4个单独的整数

转载 作者:行者123 更新时间:2023-11-30 18:14:27 26 4
gpt4 key购买 nike

我有一个程序可以读取 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;

}

在所有这些困惑中,ab 代表日期,cd 代表月份,efg 代表月份年。

此外,fflush 功能无法正常工作。它破坏了出生印记。

为了更好地理解,这是我的 emso:0701996500037。这是正常日子的结果:EMSO是合法的!

此人是男性

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

此人出生于斯洛文尼亚。

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

最佳答案

time 返回自纪元以来的秒数。 mktime 返回其 struct tm * 参数自纪元以来的秒数。因此:

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

将为您提供自日期以来经过的秒数。 (这不考虑时区。)

关于在C中以日期形式组合4个单独的整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12045626/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com