So I am trying to write a program that will display the number of days since 1/1/1753. I am not entirely sure how to do this other that to use a loop which I am not too familiar with. What I have so far is below which is very little I know I am just not sure which type of loop to use. I heard that "for" is used for counting so is that what I would be using here? And also how would I write a function to take into account a leap year.
Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
int daysYear()
{
for
}
int main()
{
int year;
cout << "Year : ";
cin >> year;
return 0;
}
However, if you want an input, just subtract 1753 from the year given, multiply by 365.25, and add the number of days passed since the start of the year.
A for loop is... really just a glorified while loop.
You're trying to get days from years... the most you can do with this is the number of days since some fixed time in one year and some fixed time within this year.
However, my above general solution should work. Just omit the final step.
int daysYear()
{
int year;
int days;
days = year - 1753 * 365;
return year;
}
int main()
{
int year;
int days;
cout << "Year : ";
cin >> year;
cout << "Number of days: " << days;
return 0;
}
I want to understand how to use loops because that is what we are learning in class right now and I don't really understand it. This isn't my exact homework assignment but the one I have to do is similar to it.
int daysYear()
{
int year;
int days;
while (days = year - 1753 * 365);
return days;
}
int main()
{
int year;
int days;
cout << "Year : ";
cin >> year;
cout << "Number of days: " << days;
return 0;
}