One last problem

I have one final problem, however I am getting an error on only 1 line for a function call, but none other, and I don't see why it would be wrong at all.

Date.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>
using namespace std;

class Date
{
private:
	int month, day, year;
public:
	Date();
	Date(int, int, int);
	~Date(){}
	void setDate();
	void setDay(int);
	void setMonth(int);
	void setYear(int);
	void showDate1();
	void showDate2();
	void showDate3();
};


Date.cpp
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

#include <iostream>
#include <string>
using namespace std;
#include "Date.h"
Date::Date()
{
	//Initialize variables.
	int month = 0, day = 0, year = 0;
}
Date::Date(int Month, int Day, int Year)
{
	month = Month;
	day = Day;
	year = Year;
}
void Date::setDay(int d)
{
	if (d < 1 && d > 31)
		cout << "The day is invalid" << endl;
	else
		day = d;

}
void Date::setMonth(int m)
{
	if (m < 1 && m > 12)
		cout << "The month is invalid" << endl;
	else
		month = m;

}
void Date::setYear(int y)
{
	if (y < 1950 && y > 2020)
		cout << "The year is invalid" << endl;
	else
		year = y;
}
void Date::showDate1()
{
	cout << month << " /" << day << " /" << year << endl;
}
void Date::showDate2()
{
	string monthName[] = { "January", "February", "March",
		"April", "May", "June", "July",
		"August", "September", "October",
		"November", "December" };
	cout << monthName[month - 1] << "  " << day << "  " << year << endl;
}
void Date::showDate3()
{
	string monthName[] = { "January", "February", "March",
		"April", "May", "June", "July",
		"August", "September", "October",
		"November", "December" };
	cout << day << "  " << monthName[month - 1] << "  " << year << endl;
}

int main()
{
	int Month, Day, Year;
	string monthName[] = { "January", "February", "March",
		"April", "May", "June", "July",
		"August", "September", "October",
		"November", "December" };


	cout << "Please enter a month (between 1 - 12) " << endl;
	cin >> Month;

	cout << "Please enter a day (between 1 - 31) " << endl;
	cin >> Day;

	cout << "Please enter a year (between 1950 - 2020) " << endl;
	cin >> Year;


	Date newDate(Month, Day, Year);
	newDate.showDate1();
	newDate.showDate2();
	newDate.showDate3();

	cin.get();
	cin.get();
	system("pause");
	return 0;
}


Assignment.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;
#include "Date.h"
int main()
{
	Date d1;
	Date d2(2, 12, 2010);
	d1.showDate1();
	d2.showDate2();
	d1.setDate(8, 29, 1986);
	d1.showDate3();
	system("pause");
	return 0;
}


It is generating an error on the Assignment.cpp,
error C2660: 'Date::setDate' : function does not take 3 arguments
IntelliSense: too many arguments in function call

The only portion it highlights is d1.setDate(8, 29, 1986);
so that means it accepted Date d2(2, 12, 2010);

It is most likely something simple like my last assignment, but i am just not seeing it.


setDate(); in the header and the cpp does not implement this method either. not mentioning also that there is two main!
still not seeing where the error is
?????
What @Ericool is saying is you have a setDate() prototype in your header file. Nowhere in your cpp file have you defined that. Also you have two mains, one in Assignment.cpp and one in Date.cpp.

And the VS compiler error you're seeing is telling you exactly as it is: because you didn't give parameter lists to your setDate() function, the compiler tracks that down and says what you're trying to do is illegal. Notice how you've set up your constructor to take three parameters; that's why it accepts d2(2, 12, 2010)
Last edited on
Topic archived. No new replies allowed.