I keep getting an error message stating that I cannot convert a string to a double in reference to line 39. Can someone review the code and let me know where I'm off? I feel that maybe line 25 should list double for the variable "R."
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Present_Value
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Declare global variables.
/* double F = int.Parse(futureTextBox.Text);
double R = int.Parse(interestTextBox.Text);
double N = int.Parse(sitTextBox.Text);*/
private double CalculateData(int F, int R, int N)
{
double P = F/(1 + R)*N;
return P ;
}
private void button1_Click(object sender, EventArgs e)
{
int n = int.Parse(sitTextBox.Text);
int f = int.Parse(futureTextBox.Text);
int r = double.Parse(intTextBox.Text);
presentValuelabel.Text = CalculateData(f,r,n).ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void exitButton_Click(object sender, EventArgs e)
{
//Close this form.
this.Close();
}
}
}
intvariable but trying to assigndoublewithdouble.Parse()method. Try to changedouble.Parse()toint.Parse().F/(1 + R)*N(as it stands in your question) is purely being calculated with integer math. So, for example, the result of(1 / (1 + 2) * 3)is0using integer math. But if I change to doubles then(1.0 / (1.0 + 2.0) * 3.0)gives1.0.