(Guru please do not post the same solution. I\'m would like to see a different s
ID: 3621288 • Letter: #
Question
(Guru please do not post the same solution. I'm would like to see a different solution in order to get a better understanding of it. Thanks)I'm in an intro to c++ class and we are doing our first lengthy assignment. I've made some progress on the program but I'm having some issues finishing it. Since I'm just in an intro class, I have trouble understanding help that is to complex. Any help would be greatly appreciated. Here is the assignment:
The Days of Our Lives
Write a program to determine the number of days between any two dates from
July 4, 1776 until now. Inclusive. You must ensure that the user enters valid dates.
This means a valid year, a valid month, and a valid day of the month.
Your program should then start at the beginning date (which must not be after
the ending date), and count each day until the ending date.
The program should print out the Month and Year as it counts (NB: not the day).
If you count a February that is in a leap year, note that in the output.
The final output will be two items: the number of days and the number of leap years
between the dates.
Thanks
Explanation / Answer
i'd create an array int month[12] ={31, 28, 31, 30, 31, 30, 31, 31, 31, 30, 31}; notice how the month corresponds to how many days are in that month int year = 0; int GivenYear=0; int GivenMonth=0; int GivenDays = 0; int EndDays = 0; int MaxYear =0; int MaxMonth =0; int totalDays = 0; int totalLeap = 0; bool leap = false; bool SameYear = false; bool sameMonth = false; int counter = 0; year = GivenYear; if (givenYear == maxYear)//special condition { sameYear = true; if (givenMonth==MaxMonth) { sameMonth = True; } else { //subtract initial days of the first month from that months total days totalDays = totalDays - GivenDays + 1 //assuming you are counting the first day //I.e. july 4th, you skip days 1 2 3, but since you are subtracting 4, add 1 back in } } else //check needed in case you are given the same month in the same year as a range { subtract initial days of the first month from that months total days totalDays = totalDays - GivenDays + 1 //assuming you are counting the first day //I.e. july 4th, you skip days 1 2 3, but since you are subtracting 4, add 1 back in } now you create a loop for the first year counter = givenMonth - 1; //note that month 1 lies in the 0th spot, etc. while (counterRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.