Calculate the interest amount paid on a given principal. - CSharp Language Basics

CSharp examples for Language Basics:decimal

Introduction

If either the principal or the interest rate is negative, generate an error message.

Demo Code

using System;/*from   ww w. j a v  a 2 s  .  c o  m*/
public class Program
{
   public static void Main(string[] args)
   {
      Console.Write("Enter principal: ");
      string principalInput = Console.ReadLine();
      decimal principal = Convert.ToDecimal(principalInput);
      Console.Write("Enter interest: ");
      string interestInput = Console.ReadLine();
      decimal interest = Convert.ToDecimal(interestInput);
      decimal interestPaid = principal * (interest / 100);
      decimal total = principal + interestPaid;
      Console.WriteLine("Principal     = " + principal);
      Console.WriteLine("Interest      = " + interest + "%");
      Console.WriteLine("Interest paid = " + interestPaid);
      Console.WriteLine("Total         = " + total);
   }
}

Result


Related Tutorials