Untitled
unknown
plain_text
a year ago
2.7 kB
11
Indexable
using System;
namespace ClassLibrary1
{
public class Class1
{
public static double r; //Rate of interest
public static double b; //Balance
public static string i; //Type of interest
public static double o; //Original Balance
public static double t = 1; //Time
public static void Main()
{
t = 1;
BalanceCheck();
RateOfInterestCheck();
TypeOfInterestCheck();
InterestFormula(i);
}
public static void BalanceCheck()
{
Console.WriteLine("Please enter your balance");
string tmp = Console.ReadLine();
if (!double.TryParse(tmp, out b) || b <= 0)
{
Console.WriteLine(tmp + " is invalid. Please input a positive number for the balance");
Main();
}
o = b;
}
public static void RateOfInterestCheck()
{
Console.WriteLine("Please enter the rate of interest ");
string tmp = Console.ReadLine();
if (!double.TryParse(tmp, out r) || r <= 0)
{
Console.WriteLine(tmp + " is invalid. Please input a positive number for the rate of interest");
Main();
}
}
public static void TypeOfInterestCheck()
{
Console.WriteLine("Please enter the type of interest (simple/compound)");
i = Console.ReadLine().ToLower();
if (i != "simple" && i != "s" && i != "compound" && i != "c")
{
Console.WriteLine(i + " is not a type of interest. Please enter either \"simple\" or \"compound\"\n");
Main();
}
}
public static void InterestFormula(string type)
{
if (type == "simple" || type == "s")
{
b = o + (o * (r / 100) * t);
}
else if (type == "compound" || type == "c")
{
b = o * Math.Pow(1 + (r / 100), t);
}
Console.WriteLine("After " + t + " years, the balance is $" + b);
CheckIfBalanceIsDoubleOriginal();
}
public static void CheckIfBalanceIsDoubleOriginal()
{
if (b >= 2 * o)
{
Console.WriteLine("It will take " + t + " years for the balance to doubled\n");
Console.WriteLine("The balance will be " + b);
Main();
}
else
{
t++;
InterestFormula(i);
}
}
}
}
Editor is loading...
Leave a Comment