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
|
#include <iostream>
#include <string>
using namespace std;
class dateclass
{
int month, day, year; // <==== NOT global;
public:
dateclass( int m, int d, int y) : month(m), day(d), year(y) { } // <==== constructor sets variables
void printMonth(); // <==== if it doesn't return anything make it void
};
void dateclass::printMonth()
{
const string names[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
if ( month < 1 || month > 12 ) cout << "Invalid month\n";
else cout << names[month-1];
}
int main()
{
int month, day, year; // <===== declare LOCAL variables here
cout << "Enter month: "; cin >> month; // <===== comma operator not appropriate here
cout << "Enter day: "; cin >> day;
cout << "Enter year: "; cin >> year;
dateclass instance(month, day, year);
instance.printMonth();
} // <===== make sure you paste ALL of your code
|