using void print()

Hello All,
I am attempting to write a program that takes a month, day and year and outputs the date in athe format Day/Month/Year...
I think I am close and dont have any errors but it may be the order I am listing my code in thats not making it work...
#include <iostream>
using namespace std;

class Date

{
public:
Date();
void setDay (int d);
void setMonth (int m);
void setYear (int y);
void print();

private:
int day;
int month;
int year;
};

Date::Date()

{
day = month = year = 1;
}

void Date::setDay (int d)
{
day = d;
}
void Date::setMonth (int m)
{
month = m;
}
void Date::setYear (int y)
{
year = y;
}
void Date::print()
{
cout << day << "/" << month << "/" << year << endl;
}

int main()

{

int m;
int d;
int y;
int day;
int month;
int year;


cout<<"\n Enter the month: ";
cin>>m;
cout<<"\n Enter the day: ";
cin>>d;
cout<<"\n Enter the year: ";
cin>>y;

void print (Date);

return 0;

}

void print (Date);
You're trying to call a function that doesn't exist.

Here is how to use class functions:

1) Create an instance of the class. For example,
Date anInstance;
2) Call that instance's class function. For example,
anInstance.setDay(4);
Last edited on
NoQuarter,
you created a class Date but you're not doing anything with it. all you did was input your m, d, y, but did nothing to create an instance of Date or call its setters to pass the value.
Also, your print method should be called like this:

1
2
//Date myDate;
myDate.print();
Thank you!
that's what I had been missing.
Topic archived. No new replies allowed.