Write a C# program to calculate simple interest.
The program should take the inputs for simple interest and display the result.
The program should ask the user to input Y if he wants to continue, else N to stop
Every time user enters Y, the program should take the inputs and calculate interest
using System;
namespace simple_interest
{
class Program
{
public static void Main(string[] args)
{
int amount, symbol;
double interest;
symbol = 0;
while (Convert.ToChar(symbol) != 'N')
{
Console.Write("Enter amount: ");
amount = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter interest: ");
interest = Convert.ToDouble(Console.ReadLine());
Console.WriteLine();
Console.WriteLine("Interest: {0:f2}", ((amount * interest)/100));
Console.WriteLine("Total: {0:f2}", (amount +((amount * interest)/100)));
Console.WriteLine("\nInput 'Y' to continue, 'N' to stop");
symbol = Console.Read();
Console.ReadLine();
while ((Convert.ToChar(symbol) != 'N')&(Convert.ToChar(symbol) != 'Y'))
{
Console.WriteLine("\nInvalid input.\nInput 'Y' to continue, 'N' to stop");
symbol = Console.Read();
Console.ReadLine();
}
}
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
Comments
Leave a comment