I'm writing a calendar program that ask for the the number of the month and the year and displays a calendar. My problem is that when it tries to print the calendar but the infinitely loops the numbers, I can't get the offset right, nether can I get the calendar header to display the right month or year.
#include <iostream>
#include <iomanip>
using namespace std;
int daysYear(int yearNumber);
int daysMonth(int monthNumber);
int offset(int yearNumber, int monthNumber, int numberofDaysinaMonth, int years\
);
int getMonth()
{
int monthNumber;
for (int a=0; a<1;)
{
cout << "Enter a month number: ";
cin >> monthNumber;
if (monthNumber < 0 || monthNumber > 12)
{
cout << "Month must be between 1 and 12.\n";
monthNumber = 0;
continue;
}
a = 1;
}
return monthNumber;
}
int getYear()
{
int yearNumber;
for(int b=0; b<1;)
{
cout << "Enter year: ";
cin >> yearNumber;
if(yearNumber < 1753)
{
cout << "Year must be 1753 or later.\n";
yearNumber = 0;
continue;
}
b = 1;
}
return yearNumber;
}
int offset(int yearNumber, int monthNumber, int numberofDaysinaMonth,
int years)
{
int days = 0;
int offsetNumber;
for(int b = 1753; b < yearNumber; b++)
{
days = days + years;
}
for(int c = 1; c < monthNumber; c++)
{
days = days + numberofDaysinaMonth;
}
offsetNumber = days % 7;
return offsetNumber;
}
int daysMonth(int monthNumber, int yearNumber)
{
int numberofDaysinaMonth;
int main(int monthNumber, int yearNumber, int offsetNumber, int numberofDaysina\
Month)
{
getMonth();
getYear();
display(monthNumber, yearNumber, offsetNumber, numberofDaysinaMonth);
return 0;
}
It shouldn't even compile, int DaysYear() has no return value. Fix this and it may compile and run. Your code is difficult to read without formatting. Use code tags and whitespace. Below are some general suggestions.
also consider const ints as apposed to magic numbers as in constint JANUARY = 1;
then use JANUARY whenever 1 means january
lastly, switch statements would make it easier to read, also faster, as in
1 2 3 4 5 6 7 8 9
switch(monthNumber)
{
case JANUARY:
// do something
break;
case FEBRUARY:
//do something
break;
}
oh and use code tags =)
edit: what IDE are you using, or are you using an IDE