これは私が取り組んでいる問題のセクションです。うるう年の部分が正しく返されていません。私はうるう年を入れたかどうかは2月29日を返します。私は間違って何をしていますか?私の関数がC言語で正しく動作しない理由
#include <stdio.h>
#include <stdbool.h>
struct date
{
int month;
int day;
int year;
};
int main (void)
{
struct date now;
void numberOfDays (struct date v);
bool findLeap (struct date v);
printf("Enter the date in this format mm/dd/yyyy: ");
scanf("%i", &now.month, &now.day, &now.year);
numberOfDays(now);
return 0;
}
void numberOfDays (struct date v)
{
int daysOfMonth;
bool findLeap (struct date v);
if (v.month == 4 || v.month == 6 || v.month == 9 || v.month == 11)
daysOfMonth = 30;
else if (v.month == 2)
{
findLeap(v);
if (findLeap)
daysOfMonth = 29;
else
daysOfMonth = 28;
}
else
daysOfMonth = 31;
printf("Number of days in month: %i", daysOfMonth);
}
bool findLeap (struct date v)
{
bool isLeap;
if (v.year % 4 == 0 && v.year % 100 != 0 || v.year % 400 == 0)
{
isLeap = true;
}
else
{
isLeap = false;
}
return isLeap;
}
あなたは 'scanf'が間違っています - フォーマット文字列には3つの値がありますが、1つだけです。 –
はい、私はそれを早めに修正しましたが、私が変更しなかったものすべてを試していました。 – crawfbigg