CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Calendars

Threaded View

  1. #1
    Join Date
    Feb 2008
    Posts
    27

    Question Calendars / array pointers

    update: down to one error
    I'm justt trying to finish up an assignment and i hit a couple snags... anyways we have to print a calendar for the years 2008 - 2099 (depending on the year a user inputs)... anyways here's how im (trying to) do it. Its a mod of a previous assignment:
    (updated)
    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    
    using namespace std;
    int yearload (int* days[12], int* startday[12], int year)
    {
    	int after8=year-2008;
    	while (after8>0, after8++)
    	{
    		int i = 0;
    		while (i<12, i++)
    		{
    			if (year%4==0)
    			{
    				*startday[i]=(*startday[i]+366)%7;
    			}
    			else
    			{
    				*startday[i]=(*startday[i]+365)%7;
    			}
    		}
    	}
    	if (year%4 == 0)
    	{
    		int days[12]={31,29,31,30,31,30,31,31,30,31,30,31};
    	}
    	else
    	{
    		int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    	}
    	return 0;
    }
    void pmonth (string month, int days, int day, int year)
    {
    	//open cal.txt, and go to eof
    	ofstream cal ("cal.txt", ios::app);
    	//print first week and white space
    	cal<<month<<"\t\t"<<year<<"\n  S  M  T  W  T  F  S\n";
    	int j = day + 1;
    	//print whitespace to move the 1st to the right spot
    	while (day > 0)
    	{
    		cal<<"   ";
    		day--;
    	}
    	
    	int date = 1;
    	while (date < days + 1)
    	{
    		//handles a new line
    		if ( j < 8 )
    		{
    			if (date < 10)
    			{
    				//theres an extra space to make everything look right (single digits)
    				cal<<"  "<<date;
    				j++;
    				date++;
    			}
    			else
    			{
    			cal<<" "<<date;
    			j++;
    			date++;
    			}
    		}
    		//print a new line if we've run beyond the end of the week
    		else
    		{
    			cal<<"\n";
    			j=1;
    		}
    	}
    	//at the end of the month print two cr's
    	if (date=date+1)
    		cal<<"\n\n";
    
    }
    int main()
    {
    	int year=2008;
    	cout<<"Enter a year: ";
    	cin>>year;
    	/*var ref:
    	month	"2008"
    	"S M T W T F S"
    	 1 2 3 4 5 6 7 <--Day
    	*/
    	string months[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
    	//these are true for 2008 (or year "0" in our model)
    	int startday[12]={2,5,6,2,4,0,2,5,1,3,6,1};
    	int days[12]={31,29,31,30,31,30,31,31,30,31,30,31};
    	yearload (&days, &startday[12], year); 
    	int day=2;
    	int i = 0;
    	while (i<12, i++)
    	{
    		pmonth (months[i], days[i], startday[i], year);
    	}
    	return 0;
    
    }
    ... I'm getting a laundry list of compile errors mostly relating to pointers. ideas?

    Update: down to one

    Here's a list of errors:
    Code:
    1>c:\users\alex smith\documents\visual studio 2008\projects\cis150a3\cis150a3\calendar.cpp(94) : error C2664: 'yearload' : cannot convert parameter 1 from 'int (*)[12]' to 'int *'
    1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    Last edited by aosmith; March 25th, 2008 at 01:41 AM. Reason: adding

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured