1 Replies - 551 Views - Last Post: 23 April 2009 - 09:09 AM Rate Topic: -----

#1 Choko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 21-April 09

Why is my private member type not being recognized?

Post icon  Posted 23 April 2009 - 09:01 AM

Well I've done all I could for this. Everything is working right except my NUM_MONTHS for some reason is not being picked up within the print function. Does anyone have any idea where I should fix this? OR what I am doing wrong. I've tried putting both statics in PRivate, public, within the function. I can't figure it out. Any help?

#include <iostream>
using namespace std;

//PART 2 of Assignment 9. 

//This program will now take a month and a day of that month and return the julian date.
//it will also show the julian date for the day before and the day AFTER.
/*EX.
	 Please give a date such as: Month Day
	 Please make sure the day you enter is appropriate for the month entered
	 
	 >> March 4
	 
	 the day before will be 122
	 March 4 would be Day 123
	 The day after will be 124*/
	 
	 class DayOfYear
	 {
		   private:
				  string month_n;
				  int day_n;
				  int julianday_n;
				  
			   
				  
		   public:
				  DayOfYear(int day)
				  {
						   day_n = day;   
				  }
				  
				  DayOfYear(string month, int julianday)
				  {
					   month_n = month;
					   julianday_n = julianday;
				  }
				  
			   
	//		   static string nummonths[NUM_MONTHS];
	  //		 static int numday[NUM_MONTHS];
				  
				
				  
		   

void printJulian()
{
	 string nummonths[] =
	 {
			"January",
			"Febuary",
			"March",
			"April",
			"May",
			"June",
			"July",
			"August",
			"September",
			"October",
			"November",
			"December"
	 };

	 int numday[] =
	 {
		 31,
		 28,
		 31,
		 30,
		 31,
		 30,
		 31,
		 31,
		 30,
		 31,
		 30,
		 31
	 };
	 
	 int j = julianday_n;
	 string m = month_n;
	 string temp;
	 
	 for(int count = 0; count < NUM_MONTHS; count++)
	 {
			 temp = nummonths[count];
			 
			 if(m == temp)
			 {
				  cout << "The Julian Date is: " << j << endl;
				  break;
			 }
			 
			 j += numday[count];
	 }
	 
	 int prev = --j;
	 if(prev == 0)
	 {
			 cout << "\nThe Previous Julian Date is: 365";
	 }
	 
	 int p = prev;
	 if(p != 0)
	 {
		  for(int month = 0; month < NUM_MONTHS; month++)
		  {
				  if(p <= numday[month])
				  {
					   cout << "The Previous Julian Date is: " << nummonths[month];
					   break;
				  }
		  p -= numday[month];
		  
		  }
	 } 
	 
	 int next = ++(++j);
	 if(next == 366)
	 {
			 cout << "\nThe Next Julian Date is: 1";
	 }
	 
	 int n = next;
	 if(n != 366)
	 {
		  for(int month = 0; month < NUM_MONTHS; month++)
		  {
				  if(n <= numday[month])
				  {
					   cout << "The Previous Julian Date is: " << nummonths[month];
				  }
				  n -= numday[month];
		  }
	 }
	 
}
};
 
int main()
{
	string month;
	int num;
	
	
	cout << "Please enter the Month: ";
	cin >> month;
	cout << "Please enter a Day in the Month: ";
	cin >> num;
	
	DayOfYear date(month, num);
	date.printJulian();
	
	
	system("Pause");
	return (0);
}
	

This post has been edited by Choko: 23 April 2009 - 09:09 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Why is my private member type not being recognized?

#2 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Why is my private member type not being recognized?

Posted 23 April 2009 - 09:09 AM

Try a #define statement.

Check the index in your text book.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1