So, i got this much done so far but im stuck and i cant get my third case statement to work, also for some reason it prints off the calendar like days 8 9 10, etc, if you copy and paste and run it you will see it doesnt line up correctly.

So, just looking for some help, maybe alittle clean up of my code etc.

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int month, days, day, count=1;

cout<<"\t\t\t\tCalendar\n";

cout<<"Enter number of month (1 for january, 2 for february...): ";
cin>>month;
cout<<"Enter day of the month (1 for Sunday, 2 for Monday...): ";
cin>>day;

if (month ==1){cout<<"\n\t\t\tJanuary\n\n"; days=31;}
if (month ==2){cout<<"\n\t\t\tFebruary\n\n"; days=28;}
if (month ==3){cout<<"\n\t\t\tMarch\n\n"; days=31;}
if (month ==4){cout<<"\n\t\t\tApril\n\n"; days=30;}
if (month ==5){cout<<"\n\t\t\tMay\n\n"; days=31;}
if (month ==6){cout<<"\n\t\t\tJun\n\n"; days=30;}
if (month ==7){cout<<"\n\t\t\tJuly\n\n"; days=31;}
if (month ==8){cout<<"\n\t\t\tAugust\n\n"; days=31;}
if (month ==9){cout<<"\n\t\t\tSeptember\n\n"; days=30;}
if (month ==10){cout<<"\n\t\t\tOctober\n\n"; days=31;}
if (month ==11){cout<<"\n\t\t\tNovember\n\n"; days=30;}
if (month ==12){cout<<"\n\t\t\tDecember\n\n"; days=31;}

cout<<"\nSun\tMon\tTue\tWen\tThu\tFri\tSat\n";

while (count<=days){
	switch(day){
	case 1:

		cout<<count<<"\t";break;

	case 2:

        cout<<"\t"<<count<<" "; break;
   
	case 3:

		cout<<"\t\t"<<count<<" "; break;}// by the way case 3 does not display correctly at all...
        count++;}

    return 0;

}

can someone give me an answer on whats wrong? its really frustrating and i wanna finish this.

What are you trying to do? can you please try to explain the logic behind this while loop?
I think you want to print out a calendar, but the logic below wont work at all.

while (count<=days){
	switch(day){
	case 1:
 
		cout<<count<<"\t";break;
 
	case 2:
 
        cout<<"\t"<<count<<" "; break;
 
	case 3:
 
		cout<<"\t\t"<<count<<" "; break;}// by the way case 3 does not display correctly at all...
        
count++; //WHY COUNT IS HERE??????
}

First try to give only following output using a loop.

1 2 3 4 5
6 7 8 9 19
11 12 13 14 15


after that..

which day of the week is starting day of the month?

ok, you dont have to worry this right now, first try to give a proper output of the calendar assuming that Monday is the 1st day of the month.

After that we can concentrate on this question.

Stop bumping your thread. It's rude! We are not staff waiting to answer your question, we are volunteers that have lives. We'll get to you when we log in and have an answer for you.

So this is my updated code, but still it isnt printing out right inside the command window. But this code is alittle bit more cleaned up and looks better and runs more efficiently, but if you seem something wrong let me know, also i have to make it print out all 12 months based on the users input but i started small doing just one month, so if u have any ideas on how i can do that please let me know.

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
	int month, days, day = 0;

	cout << "\t\t\t\tCalendar" << endl;

	cout << "Enter number of month (1 for january, 2 for february...): ";
	cin >> month;
	cout << endl << "Enter day of the month (1 for Sunday, 2 for Monday...): ";
	cin >> day;
	cout << endl;

	switch (month)
	{
	case 1:
		cout << "\t\t\tJanuary" << endl << endl;
		days = 31;
		break;
	case 2:
		cout << "\t\t\tFebruary" << endl << endl;
		days = 28;
		break;
	case 3:
		cout << endl << "\t\t\tMarch" << endl << endl;
		days = 31;
		break;
	case 4:
		cout << endl << "\t\t\tApril" << endl << endl;
		days = 30;
	case 5:
		cout << endl << "\t\t\tMay" << endl << endl;
		days = 31;
	break;
	case 6:
		cout << endl << "\t\t\tJun" << endl << endl;
		days = 30;
		break;
	case 7:
		cout << endl << "\t\t\tJuly" << endl << endl;
		days = 31;
		break;
	case 8:
		cout << endl << "\t\t\tAugust" << endl << endl;
		days = 31;
		break;
	case 9:
		cout << endl << "\t\t\tSeptember" << endl << endl;
		days = 30;
		break;
	case 10:
		cout << endl << "\t\t\tOctober" << endl << endl;
		days = 31;
		break;
	case 11:
		cout << endl << "\t\t\tNovember" << endl << endl;
		days = 30;
		break;
	case 12:
		cout << endl << "\t\t\tDecember" << endl << endl;
		days = 31;
		break;
	default:
		break;
	}

	cout << endl << "Sun\tMon\tTue\tWen\tThu\tFri\tSat" << endl;

	for (int i = 1; i <= days; ++i)
	{
			switch(day)
			{
			case 1:
				cout<< i << "\t";
				break;
			case 2:
				cout<<"\t"<< i <<" ";
				break;
			case 3:
				cout<<"\t\t"<< i <<" ";
				break;
			default:
				break;
			}
	}

	char k;
	cin >> k;
	return 0;
}
This article has been dead for over six months. Start a new discussion instead.