calender mal alignment issue



#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include<conio.h>
using namespace std;

int daysPerMonth(int month,int year);
string getMonth(int month);
int calcPush(int initDay, int dispMonth,int year);



int year, day, month,feb, errCount = 0;



void main()
{

// enter year,day and month. allows 3 errors each input or Todor boots you
cout<< "Enter the year: ";
cin >> year;

while (!cin.good())
{
while ( errCount <3 )
{
cout<<"Todor: \"Too many attempts, Goodbye\"\a"<<endl;
exit(1);
}
cout << "Enter A Valid Year\n";
cin.clear();
cin.ignore(80,'\n');
errCount++;
cin >> year;

}

cout << "Enter the day of the week the years starts" <<endl;
cout << "Sun=1 Mon=2 Tue=3 Wed=4 Thu=5 Fri=6 Sat=7"<<endl;
cin >> day;
errCount=0;

while(!cin.good() || day < 1 || day > 7)
{
while (errCount <3 )
{
cout<<"Todor: \"Too many attempts, Goodbye\"\a"<<endl;
exit(1);
}
cout << "Enter a number 1-7 for the day" << endl;
cin.clear();
cin.ignore(80, '\n');
errCount++;
cin >> day;
cout <<"\n\n\n"<<endl;
}

cout << "Enter the month to display (1-12)" << endl;
cout << "Jan=1 Feb=2 Mar=3 Apr=4 May=5 Jun=6"<< endl;
cout << "Jul=7 Aug=8 Sep=9 Oct=10 Nov=11 Dec=12"<< endl;

cin >> month;
errCount =0;

while(!cin.good() || month < 1 || month > 12)
{
while (errCount <3 )
{
cout<<"Todor: \"Too many attempts, Goodbye\"\a"<<endl;
exit(1);
}
cout << "Please enter a number 1-12" << endl;
cin.clear();
cin.ignore(80, '\n');
errCount++;
cin >> month;
cout <<"\n\n\n"<<endl;
}



int dayLimiter = daysPerMonth( month,year);
string calenderHeading = getMonth(month);


cout <<"\n\n\n"<<endl;
//universal heading pattern
cout << setw(15) << calenderHeading <<" "<< year << "\n"<< endl;
cout <<"______________________________________"<<endl;
cout <<" Sun Mon Tues Wed Thur Fri Sat" << endl;
cout <<"______________________________________"<<endl;


// fills prints the days of the week after figuring out where to start
int startDay = (calcPush(day,month,year))%7;
int counter = (calcPush(day,month,year))%7;
cout<<setw(startDay*5)<<"1";


for(int i = 2; i <= dayLimiter; i++)
{

cout << setw(5) << i;
counter++;
if(counter == 6)
{
cout<<"\n";
counter=0;
}

}

cout<<"\n\n"<<endl;

}
// switches number entered to a string display for calander heading
string getMonth(int month)
{
string header;

switch (month)
{
case 1:
header = "January";
break;
case 2:
header = "Febuary";
break;
case 3:
header = "March";
break;
case 4:
header = "April";
break;
case 5:
header = "May";
break;
case 6:
header = "June";
break;
case 7:
header = "July";
break;
case 8:
header = "August";
break;
case 9:
header = "September";
break;
case 10:
header = "October";
break;
case 11:
header = "November";
break;
case 12:
header = "December";
break;
default:
header= "Invalid";
}
return header;
}
// sets number of days per month for counter

int daysPerMonth(int month,int year)
{
int numberDays=0;
if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
{ numberDays=31;}
else if(month==4 || month==6 || month==9 || month==11)
{numberDays=30;}
else if((year%100!=0 && year%4==0) || year%400==0)
{ numberDays=29;}
else
numberDays=28;
return numberDays;
}



// based on starting day pushes out calender the
//appropriate number of days and checks for leap year
int calcPush(int initDay, int dispMonth,int year)
{
int output;

feb=28;
if((year%100!=0 && year%4==0) || year%400==0)
feb=29;

switch(dispMonth)
{
case 1:
output = 0;
break;
case 2:
output = 31;
break;
case 3:
output = 31+feb;
break;
case 4:
output = 62+feb;
break;
case 5:
output = 92+feb;
break;
case 6:
output = 123+feb;
break;
case 7:
output = 153+feb;
break;
case 8:
output = 184+feb;
break;
case 9:
output = 215+feb;
break;
case 10:
output = 245+feb;
break;
case 11:
output = 276+feb;
break;
case 12:
output = 306+feb;
break;
default:
output = 0;
break;
}

return output;
}









Without using the code format tags, you have code alignment issues too. Can you please edit your code use the code format tag to format your code, it's unreadable as is.

You can set field widths and various formats with IO stream manipulators.
http://www.cplusplus.com/reference/iostream/manipulators/
http://www.exforsys.com/tutorials/c-plus-plus/c-manipulators.html
http://www.fredosaurus.com/notes-cpp/io/omanipulators.html
only the first week of the calender is not happy. rest is fine
Topic archived. No new replies allowed.