namespace Calculating_Pricipal
{
public class Intrest
{
static void Main(string[] args)
{
Console.Write("Enter principal amount: ");
decimal principal = Convert.ToDecimal(Console.ReadLine());//here we have declared a variable principal of type decimal
//make sure that pricipal should not be in negative.
if (principal < 0)
{
Console.WriteLine("Principal cannot be negative ");
principal = 0; //declare principal is zero
}
Console.Write("Enter interest rate : ");
decimal interest = Convert.ToDecimal(Console.ReadLine());//here we have declared a variable Intrest of type decimal
if (interest < 0)
{ // interest cannot be negative
Console.WriteLine("Interest cannot be negative");
interest = 0;
}
Console.Write("Enter number of years : ");
int noYearsTime = Convert.ToInt32(Console.ReadLine());//Time is no of years
Console.WriteLine("\nPrincipal = " + principal + "\nInterest = " + interest + "%" + "\nDuration = " + noYearsTime + " years\n");
// loop through number of years specified
int year = 1;
while (year <= noYearsTime)
{
// calculate interest
decimal interestPaid = principal * (interest / 100);
// calculate new principal
principal += interestPaid;
// round to the nearest
principal = decimal.Round(principal, 2);
Console.WriteLine("Year " + year + " $ " + principal);
year++;
}
Console.WriteLine("\nPress Enter to stop");
Console.Read();