CSharp examples for Language Basics:decimal
If either the principal or the interest rate is negative, generate an error message.
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); } }