I don’t know which problems did you have writing this in C#, but the code is very simple:
var y = 20;
var p = 50000;
var r = 0.05;
var c = 6521;
var result = p * Math.Pow(1 + r, y) + c * ((Math.Pow(1 + r, y + 1) - (1 + r))/r);
JavaScript:
var y = 20;
var p = 50000;
var r = 0.05;
var c = 6521;
var result = p * Math.pow(1 + r, y) + c * ((Math.pow(1 + r, y + 1) - (1 + r))/r);
You should only assign your values to variables.
solved Calculation of Investment Balance in C# or javascripts [closed]