3 Replies - 2429 Views - Last Post: 26 October 2006 - 07:49 PM Rate Topic: -----

#1 eadams20  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 30-August 06

confused with errors on DAte of month

Posted 26 October 2006 - 03:56 PM

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>

using namespace std;



//function prototypes
void DetermineWeekDay(int, int, int, int, int, int, int, int&);




int main()
{
	int JDN;
	int day;
	int month;
	int year;
	int DayofWeek;
	int intRes1;
	int intRes2;
	int intRes3; 
	bool dataareOK = false;
	
	
	do
		{
		cout << "Please input the date month, day, year seprated by a space: ";
		cin >> month >> day >> year;
		
		if (month < 13)
		dataareOK = true;
		else
		cout << "Please enter a number smaller than 13 for the month: " 
				 << endl;
		if ( day<32);
		else
			cout << "Please enter a number smaller than 32 for the day:" 
				 << endl;
		

	} while (dataareOK == false);

	

	DetermineWeekDay (day, month, JDN, year, intRes1, intRes2, intRes3, DayofWeek);
	cin.get(), cin.get();
	return 0;
}

void DetermineWeekDay(int day, int month, int JDN, int year, int intRes1, 
					  int intRes2, int intRes3, int& DayofWeek )
{
	//Precondition: day of week must be entered
	//Postcondition: user enters correct information
	// Reference parameter DayofWeek calculated

	
	JDN = ((intRes1 + intRes2 + intRes3 + day) + 1720944.5);
	DayofWeek = ((JDN + 1) % 7);
	intRes1 = (2- year /100 + year / 400);
	intRes2 = int(365.25 * year);
	intRes3 = int(30.6001 * (month + 1));
	
		cout << " The day of the week " <<  " for " 
			 << month << day << year << "is" <<  DayofWeek;
		if (DayofWeek == 0)
		   cout << "Sunday";
		else if (DayofWeek == 1)	//Nested If
		   cout << "Monday";
		else if (DayofWeek == 2)	//Nested If
		   cout << "Tuesday";
		else if (DayofWeek == 3)	//Nested If
		   cout << "Wednesday";
		else if (DayofWeek == 4)	//Nested If
		   cout << "Thursday";
		else if (DayofWeek == 5)   //Nested If
		   cout << "Friday";
		else if (DayofWeek == 6)   //Nested If
		   cout << "Saturday";
		   cout << endl; 

return;

		

	

	


}





here are the run time errors

Symbols loaded.
No symbols loaded.
No symbols loaded.
Failure #3 - The variable 'intRes3' is being used without being defined.
Run-Time Check Failure #3 - The variable 'intRes2' is being used without being defined.
Run-Time Check Failure #3 - The variable 'intRes1' is being used without being defined.
Run-Time Check Failure #3 - The variable 'JDN' is being used without being defined.
The thread 'Win32 Thread' (0xdb8) has exited with code -1073741510 (0xc000013a).
The program '[3456] : Native' has exited with code -1073741510 (0xc000013a).


I also have a goof in the math as far as if the date is later than 10 15 1582 then I compute w/ the intRes1 formula otherwise intRes1 will be zero.. here is what I tried to insert but I got many errors.. how would I write that in.. here is what I did



if (month >> day >> year > 10 15 1582)
   intRes1 = (2- year /100 + year / 400);
else 
intRes1 = 0



Is This A Good Question/Topic? 0
  • +

Replies To: confused with errors on DAte of month

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: confused with errors on DAte of month

Posted 26 October 2006 - 04:30 PM

For the three errors, they occur becasue you are passing them to a function, and they have never been assigned any value. You are then tryting to use them in that function as if they had values - which they do not.

As for the second portion of your question, the statement you are using will not evaluate the way you think. You'll need to check each of the variables independantly, or combine them into some sort of string and compare that way.
Was This Post Helpful? 0
  • +
  • -

#3 Antiokus  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 192
  • Joined: 06-September 06

Re: confused with errors on DAte of month

Posted 26 October 2006 - 07:35 PM

I'm not sure if this is a problem in C++, I know it can be with C... but you declared JDN as an int, but when you drop to the second function you are computing it as a double (the decimal). I just compiled the code on my machine with Dev-C++ and it gave me a warning for converting the int to a double.

Amadeus is right. You arent giving those Res variables any value and so when you compute them, they are holding a lot of random numbers usually because there was already something left over in memory in the location that was allocated to it.

You can still do the checking you want with the Res variables, but you cant check the three conditions like that, they need to be seperate, or like amadeus said, placed into a string and compared that way.
Was This Post Helpful? 0
  • +
  • -

#4 eadams20  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 30-August 06

Re: confused with errors on DAte of month

Posted 26 October 2006 - 07:49 PM

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>

using namespace std;



//function prototypes
void DetermineWeekDay(float, float, float, int, int, int, int, int&);




int main()
{
	
	float day;
	float month;
	float year;
	int DayofWeek;
	int intRes1 = 0;
	int intRes2 = 0;
	int intRes3 = 0; 
	int JDN = 0; 
	bool dataareOK = false;
	do
		{
		cout << "Please input the date month ";
		cin >> month;
		cout << "Please input the date day:";
		cin >> day;
		cout << "Please input the date Year:";
		cin >> year;
		
		if (month < 13)
		dataareOK = true;
		else
		cout << "Please enter a number smaller than 13 for the month: " 
				 << endl;
		if ( day<32);
		else
			cout << "Please enter a number smaller than 32 for the day:" 
				 << endl;

		if((year > 1582) || // flags all years greater than 1582
		   (month > 10) && (year == 1582) || // flags months over 10 in 1582
		   (month == 10) && (day > 15) && (year == 1582)) // flags month 10 and days over 15 in year 1582
		
		   
{
	 // do something
}

	} while (dataareOK == false);

	

	DetermineWeekDay (day, month, JDN, year, intRes1, intRes2, intRes3, DayofWeek);
	cin.get(), cin.get();
	return 0;
}

void DetermineWeekDay(float day, float month,  float year, int JDN,int intRes1, 
					  int intRes2, int intRes3, int& DayofWeek )
{
	//Precondition: day of week must be entered
	//Postcondition: user enters correct information
	// Reference parameter DayofWeek calculated

	
	intRes1 = (2- year /100 + year / 400);
	intRes2 = int(365.25 * year);
	intRes3 = int(30.6001 * (month + 1));
	JDN = ((intRes1 + intRes2 + intRes3 + day) + 1720944.5);
	DayofWeek = ((JDN + 3) % 7);  

		cout << " The day of the week " <<  " for " 
			 << month << day << year << "is" <<  DayofWeek;
		if (DayofWeek == 0)
		   cout << "Sunday";
		else if (DayofWeek == 1)	//Nested If
		   cout << "Monday";
		else if (DayofWeek == 2)	//Nested If
		   cout << "Tuesday";
		else if (DayofWeek == 3)	//Nested If
		   cout << "Wednesday";
		else if (DayofWeek == 4)	//Nested If
		   cout << "Thursday";
		else if (DayofWeek == 5)   //Nested If
		   cout << "Friday";
		else if (DayofWeek == 6)   //Nested If
		   cout << "Saturday";
		   cout << endl; 

return;

		

	

	


}




here is how i corrected the runtime errors. It is working and running correctly now. But I did have to fudge the formula a bit on the dayofweek = I changed the 1 to a 3 so that the day of the week came out to the correct one. I don't understand why it is two days off, I was given the formulas so I know they should be correct. LOL but who knows

Emily


View PostAntiokus, on 26 Oct, 2006 - 07:35 PM, said:

I'm not sure if this is a problem in C++, I know it can be with C... but you declared JDN as an int, but when you drop to the second function you are computing it as a double (the decimal). I just compiled the code on my machine with Dev-C++ and it gave me a warning for converting the int to a double.

Amadeus is right. You arent giving those Res variables any value and so when you compute them, they are holding a lot of random numbers usually because there was already something left over in memory in the location that was allocated to it.

You can still do the checking you want with the Res variables, but you cant check the three conditions like that, they need to be seperate, or like amadeus said, placed into a string and compared that way.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1