S.Singh S.Singh - 8 days ago 19
C# Question

C# 2D arrays calendar month UI

i just need assisting on 2d arrays, what i have to do is ask user input to display the calendar month using arrays, any help is appreciated, thanks

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace calendarMonth1
{
public class Program
{
static void Main(string[] args)
{
Program calendar = new Program();
calendar.MonthNames();
calendar.ColRow();
}

public void Day()
{
Console.WriteLine();
for (int i = 1; i <= 31; i++)
{
Console.WriteLine(" ", i);
}
}

public void MonthNames()
{
int month;
int[] months = new int [12];
for (int i = 0; i < months.Length; i++)
{
month = months[i];
Console.WriteLine(month + " ");
}
}

public void ColRow()
{
int[][] months = new int[12][];

months[0] = new int [31];
months[1] = new int [28];
months[2] = new int [31];
months[3] = new int [30];
months[4] = new int [31];
months[5] = new int [30];
months[6] = new int [31];
months[7] = new int [31];
months[8] = new int [30];
months[9] = new int [31];
months[10] = new int [30];
months[11] = new int [31];
int dayNum365 = 1;
for (int month = 0; month < months.Length; month++)
{
for (int day = 0; day < months[month].Length; day++)
{
months[month][day] = dayNum365;
dayNum365++;
}
}

for (int col = 0; col < 31; col++)
{
for (int row = 0; row < 12; row++)
{
Console.WriteLine(" jan " + months[row][col]);
Console.WriteLine(" ");
}
Console.WriteLine();
}
}
}


}

what shall i do now?
this is what im suppose to do, what am i missing?

Write a program that will print a calendar for a month. The program should ask you
for the day of the week that the first day of the month falls on (numbered between 0
and 6) and how many days there are in the month. It should also ask for the name of
the month.

Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace calenderMonth1
{
    class Program
    {
    int[][] months;
    int day;

    static void Main(string[] args)
    {
        Program calendar = new Program();
        calendar.Months();
        calendar.ColRow();
    }

    public void Display(int itr)
    {
        for (int i = 0; i < itr; i ++)
        {
            Console.WriteLine();
        }
    }

    public enum MonthNames
    {
        JANUARY, 
        FEBRUARY, 
        MARCH, 
        APRIL, 
        MAY, 
        JUNE, 
        JULY,
        AUGUST, 
        SEPTEMBER,
        OCTOBER,
        NOVEMBER, 
        DECEMBER
    }
    public void Months()
    {
        int month;
        int[] months = new int[12];
        for (int i = 0; i < months.Count(); i ++)
        {
            month = months[i];
            Console.WriteLine(month + "\t");
        }
    }

    public void ColRow()
    {
        months = new int[12][];
        for (int i = 0; i < 12; i ++)
        {
            switch (i)
            {
                case 0:
                    months[i] = new int[31];
                    break;
                case 1:
                    months[i] = new int[28];    //This may not always be true...  Leap Year every 4 years
                    break;
                case 2:
                    months[i] = new int[31];
                    break;
                case 3:
                    months[i] = new int[30];
                    break;
                case 4:
                    months[i] = new int[31];
                    break;
                case 5:
                    months[i] = new int[30];
                    break;
                case 6:
                    months[i] = new int[31];
                    break;
                case 7:
                    months[i] = new int[31];
                    break;
                case 8:
                    months[i] = new int[30];
                    break;
                case 9:
                    months[i] = new int[31];
                    break;
                case 10:
                    months[i] = new int[30];
                    break;
                case 11:
                    months[i] = new int[31];
                    break;
                default:
                    break;
            }

        }

        int dayInYear = 1;
        for (int thisMonth = 0; thisMonth < months.Count(); thisMonth++)
        {
            for (day = 0; day < months[thisMonth].Count(); day++)
            {
                months[thisMonth][day] = dayInYear;
                dayInYear++;
            }

        }
        for (int row = 0; row < 12; row ++)
        {
            for (int col =0; col < months[row].Count(); col ++)     //Make sure the array doesn't go out of bounds...
            {
                switch (row)
                {
                    case 0:
                        Console.WriteLine(MonthNames.JANUARY.ToString() + "\t" + months[row][col] + "\n");
                        break;
                    case 1:
                        Console.WriteLine(MonthNames.FEBRUARY.ToString() + "\t" + months[row][col] + "\n");
                        break;
                    case 2:
                        Console.WriteLine(MonthNames.MARCH.ToString() + "\t" + months[row][col] + "\n");
                        break;
                    case 3:
                        Console.WriteLine(MonthNames.APRIL.ToString() + "\t" + months[row][col] + "\n");
                        break;
                    case 4:
                        Console.WriteLine(MonthNames.MAY.ToString() + "\t" + months[row][col] + "\n");
                        break;
                    case 5:
                        Console.WriteLine(MonthNames.JUNE.ToString() + "\t" + months[row][col] + "\n");
                        break;
                    case 6:
                        Console.WriteLine(MonthNames.JULY.ToString() + "\t" + months[row][col] + "\n");
                        break;
                    case 7:
                        Console.WriteLine(MonthNames.AUGUST.ToString() + "\t" + months[row][col] + "\n");
                        break;
                    case 8:
                        Console.WriteLine(MonthNames.SEPTEMBER.ToString() + "\t" + months[row][col] + "\n");
                        break;
                    case 9:
                        Console.WriteLine(MonthNames.OCTOBER.ToString() + "\t" + months[row][col] + "\n");
                        break;
                    case 10:
                        Console.WriteLine(MonthNames.NOVEMBER.ToString() + "\t" + months[row][col] + "\n");
                        break;
                    case 11:
                        Console.WriteLine(MonthNames.DECEMBER.ToString() + "\t" + months[row][col] + "\n");
                        break;
                    default:
                        break;
                }
            }
        }

    }



}

}