As a Newbie to C#, I have some code in C#.
The Program is a kind of Daily Money Saving Algorithm!
I'm struggling to produce the output in some alignment way as shown in below image:
Code I have written:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RemainingDaysCalculation
{
internal class DailyMoneySavingMultiplier
{
public static void Main()
{
DateTime currentDate = DateTime.Now;
int daysInYear = DateTime.IsLeapYear(currentDate.Year) ? 366 : 365;
int daysLeftInYear = daysInYear - currentDate.DayOfYear; // Result is in range 0-365.
int finisheddaysCount = daysInYear - daysLeftInYear;
Console.WriteLine("daysLeftInYear is {0}", daysLeftInYear);
Console.WriteLine("finishedDaysCount is {0}",finisheddaysCount);
int savings = (daysInYear * (daysInYear + 1)) - (finisheddaysCount * (finisheddaysCount -1));
Console.WriteLine(savings);
//Case 2:
Console.WriteLine("_________________________________");
Console.WriteLine(" Day No || Daily Saving || Total Saved");
for (int i=1; i <= daysInYear; i++)
{
Console.WriteLine("{0,-10} || {1,-10} || {2,5}", i, (i * 2), (i * (i + 1)));
//Console.Write(i);
//Console.Write(i * 2);
//Console.Write(i * (i + 1));
}
Console.WriteLine("_________________________________");
}
}
}
Output:
Update:
I have tried the 2 ways from the given workarounds in this reference, but i'm getting the exception like