EDN Admin
Well-known member
How do i alter this code so the output is the total after each year rather than each month? The interest still need to be added monthely.
using System;<br/>
using System.Collections.Generic;<br/>
using System.Linq;<br/>
using System.Text;<br/>
<br/>
<br/>
namespace ConsoleApplication1<br/>
{<br/>
class Program<br/>
{<br/>
static void Main(string[] args)<br/>
{<br/>
double sum;<br/>
double rate;<br/>
double year;<br/>
double month;<br/>
double futureSum = 0;<br/>
<br/>
<br/>
Console.Write("Enter sum: ");<br/>
sum = Convert.ToDouble(Console.ReadLine());<br/>
Console.Write("Enter year: ");<br/>
year = Convert.ToDouble(Console.ReadLine());<br/>
Console.Write("Enter rate: ");<br/>
rate = Convert.ToDouble(Console.ReadLine());<br/>
<br/>
<br/>
month = year * 12;<br/>
futureSum = sum;<br/>
for (int mthCount = 1; mthCount <= month; mthCount++)<br/>
{<br/>
<br/>
futureSum += (futureSum * rate / 100);<br/>
<br/>
Console.WriteLine("Interest on month {0} is: {1}", mthCount, futureSum);<br/>
}<br/>
<br/>
}<br/>
}<br/>
}<br/>
<br/>
View the full article
using System;<br/>
using System.Collections.Generic;<br/>
using System.Linq;<br/>
using System.Text;<br/>
<br/>
<br/>
namespace ConsoleApplication1<br/>
{<br/>
class Program<br/>
{<br/>
static void Main(string[] args)<br/>
{<br/>
double sum;<br/>
double rate;<br/>
double year;<br/>
double month;<br/>
double futureSum = 0;<br/>
<br/>
<br/>
Console.Write("Enter sum: ");<br/>
sum = Convert.ToDouble(Console.ReadLine());<br/>
Console.Write("Enter year: ");<br/>
year = Convert.ToDouble(Console.ReadLine());<br/>
Console.Write("Enter rate: ");<br/>
rate = Convert.ToDouble(Console.ReadLine());<br/>
<br/>
<br/>
month = year * 12;<br/>
futureSum = sum;<br/>
for (int mthCount = 1; mthCount <= month; mthCount++)<br/>
{<br/>
<br/>
futureSum += (futureSum * rate / 100);<br/>
<br/>
Console.WriteLine("Interest on month {0} is: {1}", mthCount, futureSum);<br/>
}<br/>
<br/>
}<br/>
}<br/>
}<br/>
<br/>
View the full article