//------------------------------------------------ // Name: Edwin Dominguez Teco // E-mail: edwindom@usc.edu //------------------------------------------------ //------------------------------------------------ //--- If you wish, you may delete the comments --- //--- below after you read them --- //------------------------------------------------ // Write your C++ program below to compute // the days in a given month/year. Be sure // to add appropriate #includes and other // necessary statements. Also be sure to add // comments and indent your code neatly. // To compile your program, click 'Build' // To run your program, click 'Run' and you should // see the output and type in input in the window // below the editor. // To submit your program, click 'Submit' and look // at the output in the bottom window to see if it // passes a few of our automated tests. // ------------ Add #includes and other statments here ---------- #include #include #include using namespace std; // Prototype for isLeapYear function bool isLeapYear(int year); // This function takes the year as an input and should // return 'true' if the year IS a leap year and 'false' // otherwise. By writing this separately and then // calling it in main(), the code for main() should be // easier and more understandable bool isLeapYear(int year) { // ---------- Add your code here ------------------ // Leap Year condition based on the module of 4 for every four year leap year // Nested Century condition based on whether year is divisible by 100 and not divisible by 400 if(year%4==0){ if(year%100==0 && year%400!=0){ return false; }else{ return true; } }else{ return false; } } int main() { // Ask user to input month and year and declare those variables cout << "Enter the desired month (1-12) and year (0000)" << endl; int userMonth, userYear; cin >> userMonth >> userYear; // Conditional for months that have 31 and 30 days // Conditional for february's days taking into account whether its a leap year or not // Conditional for anything thats outside the 1 to 12 monthly range if(userMonth == 1 || userMonth == 3 || userMonth == 5 || userMonth == 7 || userMonth == 8 || userMonth == 10 || userMonth == 12){ cout << "There are 31 days in this month!" << endl; }else if(userMonth == 4 || userMonth == 6 || userMonth == 9 || userMonth == 11){ cout << "There are 30 days in this month!" << endl; }else if(userMonth == 2 && isLeapYear(userYear)== true ){ cout << "There are 29 days in this month!" << endl; }else if(userMonth == 2 && isLeapYear(userYear)== false ){ cout << "There are 28 days in this month!" << endl; }else if(userMonth > 12 || userMonth < 1){ cout << -1<< endl; } return 0; }