I have code for this program but it still shows me errors. Please help me to cod
ID: 3808615 • Letter: I
Question
I have code for this program but it still shows me errors. Please help me to code it correctly with output.
Here is the code but it's incorrect:
#include <iostream>
using namespace std;
bool isLeapYear(int y) {
if (y % 4 != 0) return false;
if (y < 1582) return true;
return (y % 100 != 0) || (y % 400 == 0);
}
int main() {
int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
int month, year, addDay = 0;
cout<<"Enter a number(-1 to quit): ";
cin >> month;
while(month != -1){
if(month < 1 or month > 12) {
cout<<"Invalid month"<<endl;
}
else{
if(month == 2){
cout<<"Enter the year: ";
cin >> year;
addDay = 0;
if(isLeapYear(year)){
addDay = 1;
}
}
cout<<"Number of days in month "<<month<<" is "<<(days[month-1]+addDay)<<endl;
}
cout<<"Enter a number(-1 to quit): ";
cin >> month;
}
return 0;
}
Explanation / Answer
#include using namespace std; int main() { int year; cout > year; if (year % 4 == 0) { if (year % 100 == 0) { if (year % 400 == 0) coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.