Day and date validation

Input
16/05/2017, Tuesday
08/04/2017, Saturday
18/03/2017, Saturday
18/07/2017, Tuesday
16/01/2017, Monday
29/12/2017, Friday

I have 10000++ input in txt file like that. Can someone help me improve the code? Thank you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  #include<iostream>
#include<fstream>
#include<string>
#include<cmath>
using namespace std;

int main(void)
{
	string inputFilename, s;
	string nameDays[7] = { "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" };
	ifstream inFile;
	ofstream outFile1, outFile2;
	int date, month, year, day;
	int days[7];
	int total = 0, valid = 0, error = 0;
	int leapyear;
	double Sun = 0, Mon = 0, Tues = 0, Wed = 0, Thu = 0, Fri = 0, Sat = 0;

	inFile.open("Date.txt");
	outFile1.open("Valid dates.txt");
	outFile2.open("Invalid dates.txt");

	if (inFile)
	{
		cout << "Open successfully\n";
	}
	else
	{
		cout << "Error opening file";
	}
	for (int i = 0; i < 7; i++)
	{
		days[i] = 0;
	}
	while (!inFile.eof())
	{
		getline(inFile, s);

		if (s.compare(12, 6, "Sunday") == 0) {
			days[0] ++;
		}
		else if (s.compare(12, 6, "Monday") == 0) {
			days[1]++;
		}
		else if (s.compare(12, 7, "Tuesday") == 0) {
			days[2]++;
		}
		else if (s.compare(12, 9, "Wednesday") == 0) {
			days[3]++;
		}
		else if (s.compare(12, 8, "Thursday") == 0) {
			days[4]++;
		}
		else if (s.compare(12, 6, "Friday") == 0) {
			days[5]++;
		}
		else if (s.compare(12, 8, "Saturday") == 0) {
			days[6]++;
		}
		++total;
		cout << "Total Record : " << total << endl;

		for (int i = 0; i < 7; i++)
		{
			cout << nameDays[i] << " :\t " << days[i] << endl;
		}
	}
	
	
	if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
	{
		leapyear = 1;
	}
	if (month < 13)
	{
		if (month == 1 || (3 || (5 || (7 || (8 || (10 || (12)))))))
		{
			if (date <= 31)
			{
				return true;
			}
		}
		else if (month == 4 || (6 || (9 || (11))))
		{
			if (date <= 30)
			{
				return true;
			}
		}
		else
		{
			if (leapyear == 1)
			{
				if (date <= 29)
				{
					return true;
				}
			}
			if (leapyear == 0)
			{
				{if (date <= 28)
					return true; }
			}
		}

		inFile.close();
		outFile1.close();
		outFile2.close();

		system("PAUSE");
		return 0;
	}
}
The best advise I can give is that if you want someone to read your code you should add comments. In fact, if you plan to read your code again, say in a week or a year, you should add comments.

You declare variables but never use them.
string inputFilename, s;

Below if you can't open the file, the rest of the program still tries to run.

1
2
3
4
5
6
7
8
	if (inFile)
	{
		cout << "Open successfully\n";
	}
	else
	{
		cout << "Error opening file";
	}



The next part doesn't seem to do anything.
1
2
3
4
	for (int i = 0; i < 7; i++)
	{
		days[i] = 0;
	}



Topic archived. No new replies allowed.