Here's the prompt: Write a program
that prints a calendar for one month. Input
consists of an integer specifying the first
day of the month (1 = Sunday) and an
integer specifying how many days are
in a month.
Here is a sample output of what it should look like:
First day of the month 3
Number of days in the month 31
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
namespace Program_202t
{
class Program
{
static void Main(string[] args)
{
Console.Title = "Program 202t";
Console.Write("Enter the first day of the month: ");
int year = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the number of days in a month: ");
int month = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nSunday Monday Tuesday Wedsnesday Thursday Friday Saturday");
if (year == 1)
{
Console.SetCursorPosition(0, 4);
for (int i = 1; i <= 10; i++)
{
Console.Write(i + " ");
if (((i) % 7) > 0)
{
}
else
{
Console.Write("\n");
}
}
Console.Write("\b");
for (int b = 11; b <= month; b++)
{
if (((b) % 7) > 0)
{
Console.Write(b + " ");
}
else
{
Console.Write(b + "\n");
}
}
}
if (year == 2)
{
//Console.SetCursorPosition(10, 4);
for (int i = 1; i <= month; i++)
{
if (i == 1)
{
Console.Write(" " + i + " ");
}
else if (i > 1 && i < 11 && i != 6)
{
Console.Write(i + " ");
}
Console.Write("\b");
if (i == 6)
{
Console.Write(i + "\n");
}
if (i > 11 && i != 14)
{
Console.Write(i + " ");
}
if (i == 14)
{
Console.Write(i + "\n");
}
/*if (((i) % 6) > 0)
{
}
else
{
Console.Write("\n");
}
}
Console.Write("\b");
//FIX!!!
for (int b = 11; b <= month; b++)
{
if (((b) % 13) > 0 && b >13)
{
Console.Write(b + " ");
}
if (((b) % 20) > 0 && b <= 13)
{
Console.Write(b + " ");
}
else
{
Console.Write("\n");
}
}*/
}
if (year == 3)
{
Console.SetCursorPosition(20, 4);
for (int i = 1; i <= 10; i++)
{
Console.Write(i + " ");
if (((i) % 5) > 0)
{
}
else
{
Console.Write("\n");
}
}
Console.Write("\b");
for (int b = 11; b <= month; b++)
{
if (((b) % 7) > 0)
{
Console.Write(b + " ");
}
else
{
Console.Write("\n");
}
}
}
if (year == 4)
{
for (int i = 1; i <= 10; i++)
{
Console.Write(i + " ");
if (((i) % 7) > 0)
{
}
else
{
Console.Write("\n");
}
}
Console.Write("\b");
for (int b = 11; b <= month; b++)
{
if (((b) % 7) > 0)
{
Console.Write(b + " ");
}
else
{
Console.Write(b + "\n");
}
}
}
if (year == 5)
{
for (int i = 1; i <= 10; i++)
{
Console.Write(i + " ");
if (((i) % 7) > 0)
{
}
else
{
Console.Write("\n");
}
}
Console.Write("\b");
for (int b = 11; b <= month; b++)
{
if (((b) % 7) > 0)
{
Console.Write(b + " ");
}
else
{
Console.Write(b + "\n");
}
}
}
if (year == 6)
{
for (int i = 1; i <= 10; i++)
{
Console.Write(i + " ");
if (((i) % 7) > 0)
{
}
else
{
Console.Write("\n");
}
}
Console.Write("\b");
for (int b = 11; b <= month; b++)
{
if (((b) % 7) > 0)
{
Console.Write(b + " ");
}
else
{
Console.Write(b + "\n");
}
}
}
if (year == 7)
{
for (int i = 1; i <= 10; i++)
{
Console.Write(i + " ");
if (((i) % 7) > 0)
{
}
else
{
Console.Write("\n");
}
}
Console.Write("\b");
for (int b = 11; b <= month; b++)
{
if (((b) % 7) > 0)
{
Console.Write(b + " ");
}
else
{
Console.Write(b + "\n");
}
}
}
Console.ReadLine();
}
}
}
Will this do?
class Program
{
static void Main(string[] args)
{
Console.Title = "Program 202t";
Console.Write("Enter the first day of the month: ");
int startingDay = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the number of days in a month: ");
int daysInMonth = Convert.ToInt32(Console.ReadLine());
List<string> daysOfTheWeek = new List<string>() {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
foreach (string day in daysOfTheWeek)
{
Console.Write($"{day,10}");
}
List<string> days = new List<string>();
for (int i = 0; i < startingDay; i++)
{
days.Add($"{"",10}");
}
for (int i = 1; i < daysInMonth+1; i++)
{
days.Add($"{i,10}");
}
for (int i = 0; i < days.Count; i++)
{
if (i%7!=0) {Console.Write(days[i]);}
else {Console.WriteLine(days[i]);}
}
}