I'm stumped on an exercise problem at the end of a chapter on my book. An earlier problem had me create an algorithm to calculate compound interest (this is using C# by the way). That was simple enough. A few questions later, it mentioned how some other languages don't have the decimal type and to modify the previous algorithm so that all monetary values are of type int. Seemed like a simple enough problem, converting the dollar amounts to pennies, etc. But I can't get the calculation to output what it needs to.
Any help? I've been looking at this problem for too long now lol
using System;
public class Interest
{
public static void Main( string[] args )
{
int amount; // amount on deposit at end of each year
int principal = 100000; // initial amount before interest
double rate = 0.05; // interest rate
// display headers
Console.WriteLine( "Year{0,20}", "Amount on deposit" );
// calculate amount on deposit for each of ten years
for ( int year = 1; year <= 10; year++ )
{
// calculate new amount for specified year
amount = principal * ( Math.Pow (1 + rate, year));
// display the year and the amount
Console.WriteLine( "{0,4}{1,20:C}", year, amount );
} // end for
} // end Main
} // end class Interest