|
-
February 13th, 2011, 07:40 AM
#1
Having trouble with compound interest program
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//prompt user to enter principal
Console.WriteLine( "enter principle:");
string principalInput = Console.ReadLine();
double principal = Convert.ToDouble(principalInput);
//make sure princiapl is not negative
if (principal < 0)
{
Console.WriteLine("Principal cannot be negative");
principal = 0;
}
//enter intrest rate
Console.WriteLine("enter intrest rate");
string intrestInput = Console.ReadLine() ;
double intrest = Convert.ToDouble(intrestInput);
//make sure intrest is not negative.
if (intrest < 0)
{
Console.WriteLine("intrest cannot be negative");
intrest = 0;
}
//calculate the value of principal plus intrest.
double intrestPaid= principal*(intrest/100);
//now calculate the total
double total = principal + intrestPaid;
// output the result
Console.WriteLine();//skip a line
Console.WriteLine("principal =" +principal);
Console.WriteLine("Intrest ="+ intrest + "%");
Console.WriteLine();
Console.WriteLine("intrest paid =" +intrestPaid);
Console.WriteLine("Total =" +total);
Console.WriteLine("If you want compound intrest enter the number of years,if not close now");
string years1=Console.ReadLine();
double years2 = Convert.ToDouble(years1);
double CompoundIntrest = principal * ((double)Math.Pow(1.0+intrest, years2));
Console.WriteLine("Compound intrest is" +CompoundIntrest);
//Wait for response then tell the user how to leave
Console.WriteLine ("Press Enter to Terminate...");
Console .Read() ;
I beleive the error here is that i have used Math.Pow which is what my friend has told me to use
the purpose i to figure out a compound intrest so if the princaple is 100 and teh intrest 10 and years is 2 i should get 121
can somebody rewrite this for me and tell me what would work
thank you forums
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|