C 请帮忙。功能不打印

C 请帮忙。功能不打印,c,function,C,Function,救命,我的投票功能不是打印任何声明。该函数应该根据某人的生日来计算他能参加多少次选举,但不确定为什么该函数没有根据if语句打印任何内容。如果需要查看我正在尝试执行的操作,请运行该程序 #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> //Prototype double calc_age(const unsigned int m, const un

救命,我的投票功能不是打印任何声明。该函数应该根据某人的生日来计算他能参加多少次选举,但不确定为什么该函数没有根据if语句打印任何内容。如果需要查看我正在尝试执行的操作,请运行该程序

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

//Prototype
double calc_age(const unsigned int m, const unsigned int d, const unsigned int y);
void yearToVote(int daysAge, int birthDay, int birthMonth);
void ageNextElection(AgeinDays);

int main()
{
    int month, day, year, AgeinDays;



    printf("Enter birthday (mm): ");
    scanf("%d", &month);
    printf("Enter birthday (dd): ");
    scanf("%d", &day);
    printf("Enter birthday (yyyy): ");
    scanf("%d", &year);
//Call
    AgeinDays = calc_age(month, day, year);
    printf("%d \n", AgeinDays -1);

    ageNextElection(AgeinDays);

    yearToVote(AgeinDays, day, month);

}

//First Function: Calculates Age in Days
double calc_age(const unsigned int m1, const unsigned int d1, const unsigned int y1) {  //unsigned - can't be negative.  const- can't be cahnged


    struct tm t = {0};
    time_t t_of_day;

    t.tm_year = y1 - 1900;
    t.tm_mon = m1 -1;
    t.tm_mday = d1;
    t.tm_isdst = -1;
    t_of_day = mktime(&t);

    time_t now;
    time(&now);

    return  round((difftime(now,t_of_day)/(60.0*60.0*24.0)));
}

//Second Function: How many times and years voted
void yearToVote(int daysAge, int Bday, int Bmonth)
{
int A, B, m[11] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 374}, monthsDay;

A = daysAge/365;

if (Bmonth == 1){
    monthsDay = m[0];

}
if (Bmonth == 2){
    monthsDay = m[1];

}
if (Bmonth == 3){
    monthsDay = m[2];

}
if (Bmonth == 4){
    monthsDay = m[3];

}
if (Bmonth == 5){
    monthsDay = m[4];

}
if (Bmonth == 6){
    monthsDay = m[5];

}
if (Bmonth == 7){
    monthsDay = m[6];

}
if (Bmonth == 8){
    monthsDay = m[7];

}
if (Bmonth == 9){
    monthsDay = m[8];

}
if (Bmonth == 10){
    monthsDay = m[9];

}
if (Bmonth == 11){
    monthsDay = m[10];

}
if (Bmonth == 12){
    monthsDay = m[11];

}

B = Bday + monthsDay;


if (A >= 18){
    if (daysAge <= 1986 && daysAge >= 1980 && B <= 307) {
            printf ("You could have voted in the last 4 elections and this election.\n");
    } else if (daysAge <= 1990 && daysAge > 1986 && B <= 307) {
            printf ("You could have voted in the last 3 elections and this election.\n");
    } else if (daysAge <= 1994 && daysAge > 1990 && B <= 307) {
            printf ("You could have voted in the last 2 elections and this election.\n");
    } else if (daysAge <= 1998 && daysAge > 1994 && B <= 307) {
            printf ("You could have voted in the last election and this election.\n");
    } else if (daysAge <= 2002 && daysAge > 1998 && B <= 307) {
            printf ("You can vote in this election.\n");
    } else if (daysAge >= 2002 && B > 307) {
            printf("You are not eligible to vote.\n");
}

}

}

//Third Function: Age in Eligibility of next election
void ageNextElection(int AgeinDays){
    int AgeinNext;
    AgeinDays = AgeinDays + 1460;

    AgeinNext = AgeinDays / 365;

    printf("Your age in the next election is: %d \n", AgeinNext);

    if(AgeinNext >= 18){
        printf("You are eligible to vote next election! \n");
    }
    else{
        printf("You will not be eligible to vote \n");
    }

}
#包括
#包括
#包括
#包括
//原型
双计算年龄(常数无符号整数m、常数无符号整数d、常数无符号整数y);
void yearToVote(int daysAge、int生日、int生日月);
选举无效(AgeinDays);
int main()
{
整数月、日、年、日;
printf(“输入生日(mm):”;
scanf(“%d”和“月”);
printf(“输入生日(dd):”;
scanf(“%d”、&day);
printf(“输入生日(yyyy):”;
scanf(“%d”和“年”);
//召唤
年龄天数=计算年龄(月、日、年);
printf(“%d\n”,年龄天数-1);
代理选举(AgeinDays);
投票年份(年龄、天数、月份);
}
//第一个函数:以天为单位计算年龄
双计算年龄(常数无符号整数m1、常数无符号整数d1、常数无符号整数y1){//无符号-不能为负。常数-不能为空
struct tm t={0};
一天中的时间;
t、 tm_年=y1-1900;
t、 tm_mon=m1-1;
t、 tm_mday=d1;
t、 tm_isdst=-1;
t_of_day=mktime(&t);
现在是时候了;
时间(现在);
返回回合((difftime(现在,天的时间)/(60.0*60.0*24.0));
}
//第二个功能:投票次数和年份
投票无效年份(整数日、整数日、整数月)
{
INTA,B,m[11]={0,31,59,90,120,151,181,212,243,273,304,374},月日;
A=日/365;
如果(b月==1){
月日=m[0];
}
如果(b月==2){
月日=m[1];
}
如果(b月==3){
月日=m[2];
}
如果(b月==4){
月日=m[3];
}
如果(b月==5){
月日=m[4];
}
如果(b月==6){
月日=m[5];
}
如果(b月==7){
月日=m[6];
}
如果(b月==8){
月日=m[7];
}
如果(b月==9){
月日=m[8];
}
如果(b月==10){
月日=m[9];
}
如果(b月==11){
月日=m[10];
}
如果(b月==12){
月日=m[11];
}
B=B天+月日;
如果(A>=18){

如果(daysAge=1980&&B在我的计算机上,您的代码似乎正常:

Enter birthday (mm): 01
Enter birthday (dd): 01
Enter birthday (yyyy): 2000
7611
Your age in the next election is: 24
You are eligible to vote next election!
当然,还有一些问题需要解决:

src/main.c:132:1: warning: parameter names (without types) in function declaration
  132 | void ageNextElection(AgeinDays);
      | ^~~~
src/main.c: In function 'yearToVote':
src/main.c:178:70: warning: excess elements in array initializer
  178 | int A, B, m[11] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 374}, monthsDay;
      |                                                                      ^~~
src/main.c:178:70: note: (near initialization for 'm')

“不确定函数为什么不打印”。使用调试器的最佳时机。在调试器中逐行检查代码,并在其运行时检查变量值。之后,如果您仍然需要帮助,请提供准确的测试输入、预期结果和实际结果。为什么需要所有这些
if
语句?只需使用
monthsDay=m[bmmonth-1]
已经开始工作了,谢谢。