Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem Instructions Warning: Please follow the exact output format given in the

ID: 3629910 • Letter: P

Question

Problem Instructions

Warning: Please follow the exact output format given in the examples. Otherwise your program will not be graded by the system properly.

Write a function named `dayCount()` that accepts a month, day, and year as its input arguments; calcuates an integer representing the total number of days from the turn of the century to the date that's passed; and returns the calculated integer to the calling function. For this problem, assume each year has 365 days and each month has 30 days.

You need to write a main function to prompt for year, month and day. You need to validate the input and ask user reenter one if not correct. Note you should use exact function name in your program.

Example 1:
Enter a correct year (>=0): -5
Enter a correct year (>=0): 2001
Enter a correct month (>=1 and <=12): 15
Enter a correct month (>=1 and <=12): 1
Enter a correct day: -12
Enter a correct day: 36
Enter a correct day: 15
The total days are: 380

Example 2:
Enter a correct year (>=0): 3045
Enter a correct month (>=1 and <=12): 1
Enter a correct day: 15
The total days are: 16440

Explanation / Answer

It's usually good practice to try to do it yourself. It's pretty straightforward.

You'll need to learn how to accept input (assuming c++ then mostly using "cin" and "cout").

And then calcuating the days since century change is pretty straightforward just multiply the months by 30 (subtract 1 since we shouldn't be adding days until we are past January) and then just multiply the years by 365 (we mod by 1000 to just get years after century).

#include <iostream>  // Header for IO

using namespace std;

 

int dayCount(int day, int month, int year) {

int yearDifference = year % 1000;

int monthDifference = month - 1;

return yearDifference*365 + monthDifference*30 + day;

}

 

int main() {

int year = -1, month = -1, day = -1;

 

while (year < 0) {

cout << "Enter a correct year (>=0): ";

cin >> year;

}

 

while (month < 1 || month > 12) {

cout << "Enter a correct month (>=1 and <=12): ";

cin >> month;

}

 

while (day < 0 || day > 30) {

cout << "Enter a correct day: ";

cin >> day;

}

 

cout << "The total days are: " << dayCount(day, month, year) << endl;

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote