"button2" By GGMethos (https://pastebin.com/u/GGMethos) URL: https://pastebin.com/nBqscHfh Created on: Saturday 8th of March 2014 12:02:13 PM CDT Retrieved on: Monday 26 of October 2020 05:55:49 AM UTC private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { if (textBox2->Text == "" && textBox1->Text != "" && textBox3->Text != "" && textBox4->Text != "") { double loanAmount2 = System::Convert::ToDouble(textBox1->Text); double payment2 = System::Convert::ToDouble(textBox4->Text); double numberOfMonths2 = System::Convert::ToDouble(textBox3->Text); double initial2 = (2 * (numberOfMonths2 * payment2 - loanAmount2) / (numberOfMonths2 * loanAmount2)); double rOld2 = (initial2 * (pow((1 + initial2), numberOfMonths2)) / ((pow((1 + initial2), numberOfMonths2) - 1))) - (payment2 / loanAmount2); double b2 = payment2 * pow((1. + rOld2), -numberOfMonths2); double c2 = (rOld2 * loanAmount2); double num2 = payment2 - (b2 - c2); double denom2 = numberOfMonths2 * (payment2 * pow((1. + rOld2), (-numberOfMonths2 - 1)) - loanAmount2); bool terminate2 = false; double rNew2; while (terminate2 == false) { //terminating factor to exit the loop rNew2 = rOld2 - (num2 / denom2); if (fabs(rNew2 - rOld2) >= 0.01) //loops until difference is less than .01, then terminates { rOld2 = rNew2; } else { terminate2 = true; } textBox2->Text = System::Convert::ToString(rNew2); //outputs desired results } } else{ std::cout << "Something went wrong! Please check the button you pressed and what values you entered! You may have entered in a value for what you are calculating, which is not allowed. The textbox for the ouput needs to be cleared before you call the function." << std::endl; errorProvider1->SetError(textBox2, "Please keep this blank to calculate the interest rate."); //error check } }