using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DebtCalculator
{
class Program
{
static void Main(string[] args)
{
double creditcardbalance;
Console.WriteLine("Enter in credit card balance:");
creditcardbalance = double.Parse(Console.ReadLine());
double monthlypayementamount;
Console.WriteLine("Enter in the monthly payement amount:");
monthlypayementamount = double.Parse(Console.ReadLine());
double percentagerate;
Console.WriteLine("Enter in annual percentage rate:");
percentagerate = double.Parse(Console.ReadLine());
int payoff;
double dailyinterestrate;
dailyinterestrate = percentagerate / 365;
payoff = -(1 / 30) * Math.Log(1 + creditcardbalance / monthlypayementamount (1 - (1 + dailyinterestrate), Math.Pow(0, 30))) / Math.Log(1 + dailyinterestrate);
}
}
}
the "payoff = -(1 / 30) * Math.Log(1 + creditcardbalance / monthlypayementamount " where it says monthlypayementamount it returns an error of "method name expected" how do i resolve?
Looking at the formula your equation should be like this.
payoff = -(1d / 30) * Math.Log(1 + creditcardbalance / monthlypayementamount * (1 - Math.Pow(1 + dailyinterestrate, 30))) / Math.Log(1 + dailyinterestrate);
Your problems. in mathematics p(2)
may translate to p*(2)
but in coding you have to write everything p*(2)
.
And the part Math.Pow(0,30)
evaluates to 0^30
. you have to put 1 + dailyinterestrate
(according to formula) instead of 0.
Also the result of this equation is type of double. but payoff
as i see now is type of int
. change the type of payoff to double or cast the result to int.
The other problem is -(1/30)
. they are both integer
means the result is without decimal. so put d
after the number so it will be type of double which holds decimal part. thanks to @ASH
You must Write the result in the console with Console.WriteLine()
method
your code should look like this.
double payoff;
double dailyinterestrate;
dailyinterestrate = percentagerate / 365;
payoff = -(1d / 30) * Math.Log(1 + creditcardbalance / monthlypayementamount * (1 - Math.Pow(1 + dailyinterestrate, 30))) / Math.Log(1 + dailyinterestrate);
Console.WriteLine(payoff);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.