2 Replies - 244 Views - Last Post: 31 January 2013 - 03:25 PM Rate Topic: -----

#1 HKCHaN92  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 85
  • Joined: 23-July 11

Program not initializing the date correctly

Posted 31 January 2013 - 01:47 PM

So for this assignment our teacher provided most of the code and had us implement the Initialize, GetMonthAsString, leapYear, and Adjust functions. The code compiles but it is not recognizing the date entered by the user. I don't know what to do and even the teacher didn't know what I had done wrong. I think he is new and he even stated that he doesn't know C++ all that well so I'm not sure why he is teaching this class. So I was hoping someone on here could help because I can't figure out what's wrong. I'm assuming it has to be this Initialize function:
void DateType::Initialize (int newMonth, int newDay, int newYear)
// Post: If newMonth, newDay and newYear represent a valid date,
//       year is set to newYear;
//       month is set to newMonth;
//       day is set to newDay;
//       otherwise a string exception is thrown, stating the
//       first incorrect parameter.
{
         if (newYear > 1900)
	     newYear = year;
	 else
	     throw string("Year Invalid");
		
	 if (newMonth < 13 || newMonth > 0)
	     newMonth = month;
	 else
	     throw string("Month Invalid");

	 if(newDay < daysInMonth[month] || newDay > 0)
	     newDay = day;
	 else
	     throw string("Day Invalid");
}





Thanks in advance for any help!

This post has been edited by HKCHaN92: 31 January 2013 - 09:11 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Program not initializing the date correctly

#2 #define  Icon User is online

  • Duke of Err
  • member icon

Reputation: 1330
  • View blog
  • Posts: 4,559
  • Joined: 19-February 09

Re: Program not initializing the date correctly

Posted 31 January 2013 - 02:01 PM

For a start you are assigning to the parameter and not the data member.

10         newYear = year;



whereas you want the reverse.

10          year = newYear;




:D

This post has been edited by #define: 31 January 2013 - 02:02 PM

Was This Post Helpful? 1
  • +
  • -

#3 HKCHaN92  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 85
  • Joined: 23-July 11

Re: Program not initializing the date correctly

Posted 31 January 2013 - 03:25 PM

View Post#define, on 31 January 2013 - 03:01 PM, said:

For a start you are assigning to the parameter and not the data member.

10         newYear = year;



whereas you want the reverse.

10          year = newYear;




:D/>


*facepalm* I feel kind of dumb for not noticing that. Thanks for pointing it out! I already solved the other problems with the code so this problem is officially solved! Thanks again #define!
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1