I've been reading this forum for several weeks now, trying to wrap my head around the world of c++ programming. I have found that this website is an excellent resource and I am grateful to all of you for taking the time to help noobs such as myself understand this stuff.
Anyway, my question is this. I am writing a calendar program for a class that I am taking. The program is about 90% done, however I am having a problem. My code is supposed to output a calendar for a specific month and year, and the code that I have written is generating a calendar for an entire year.
I'm just looking for pointers to steer me in the right direction. I'm assuming that it has something to do with the "string" statement in the printMonth section, but I am not sure how to remedy it. Any and all help is appreciated, thanks in advance!
Here is my code.
/*********************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
void printmonth(const int month, const int startday, const bool leap);
void printyear(const int year);
int dayofweek(const int day, const int month, const int year);
int dayofweek(const int day, const int month, const int year)
{
int a,y,m;
a=(14-month)/12;
y=year-a;
m= month+12*a-2;
return (day+y+y/4-y/100 + y/400 + (31*m/12))%7;
}
/***********************************************************************/
void printmonth(const int month, const int startday, const bool leap)
{
//Makes the arrays for the days of the week, the months,
//the days in each in month,and changes the days in Feb to
//29 if leap is true.
The problem stemmed from your void printyear(constint year) function. You have a loop to cycle through all 12 months. I made a small change to the function so that it also passes the month variable and took out the loop. The only other problem I see, is that the first of the month is not being printed under the correct day location.