hello i am trying to calculate an interest table and have made my code but cannot get the program to add from the existing principal balance to the new amount to calculate the interest gained over n amount of years. any help would be awesome. heres my code

using System;

namespace week0502
   class Interest
      static void Main(string[] args)
         decimal p = 0; // principle
         decimal r = 1; // interest rate
         decimal t = 2; // time/years entered
         decimal i = 3; // interest
         decimal a = 4; // new amount

         // prompt for values
         Console.Write("Enter original deposit amount: ");
         p = Convert.ToDecimal(Console.ReadLine());
         Console.Write("Enter annual interest rate (10% as 10): ");
         r = Convert.ToDecimal(Console.ReadLine());
         Console.Write("Enter years to save this deposit amount: ");
         t = Convert.ToDecimal(Console.ReadLine());

         // display headers
         Console.WriteLine("Year Rate Amount  Interest  New Amount");

         // calculate new amount on deposit after t amount of years
         for (int n = 1; n <= t; n++)
               // calculations
               i = p * r;
               a = i + p;

               // display contents
               Console.WriteLine("{0, 4}{1, 4}{2, 10:C}{3, 5}{4, 10:C}", n, r, p, i, a);
            } // end for
      } // end main
   } // end class
} // end namespace
8 Years
Discussion Span
Last Post by jonsca

Shouldn't line 32 just be p = i+p; (or p+=i; )? That way you put your interest into principal and iterate again.

Edited by jonsca: n/a


yea that works. thanks! how do i get the program to clear and then replay instead of exiting???


put a do-while loop around the whole thing, prompting the user at the end

string response;
      //your code here
      response = Console.ReadLine();
}(while response != "Yes" && response !="yes") ;

Edited by jonsca: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.