I'm just get started learning C++.
And I'm trying to write code that prints out the last date of the month from given the year and month. Leap years have to be considered.
I think I do something wrong.
If I put 2020 then 2 output should be 29.
Or I put 2018 then 4 output should be 30.
Please give me any kind of hint.
#include <iostream>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main()
{
int loopNum;
ifstreeam infile("input2.txt");
infile >> loopNum;
for (int i = 0; i < loopNum; i++) {
int year;
infile >> year;
int month;
infile >> month;
if (year) = year % 4 == 0 or year % 400 == 0;
if month == 2
cout << "29" << endl;
else if (month) = 2
cout << "28" << endl;
else if (month) = 1, 3, 5, 7, 8, 10, 12
cout << "31" << endl;
else
cout << "30" << endl;
}
infile.close();
return 0;
}