Hello All,
I am taking a class using Visual Studio C++ Express 2010 and on one of the first projects i need to use the Math::Pow() function. The book does not do a good job of explaining how to use this. I was able to create the program and calculate simple interest fine with a normal formula however once I needed to calculate compounded interest it required a exponent.
Line 203 of the Code is where the error is.
"error C2660: 'System::Math:: Pow' : function does not take 1 arguments"
I hope this clarifies my issue.
Thanks in advance,
Richard
Formulas used:
Simple Interest = Principal * (1 + (Years * Rate))
Compound Interest = Principal * (1 + Rate)^Years
This is the Line of code that is giving me this error:
Here is all of the program.
I am taking a class using Visual Studio C++ Express 2010 and on one of the first projects i need to use the Math::Pow() function. The book does not do a good job of explaining how to use this. I was able to create the program and calculate simple interest fine with a normal formula however once I needed to calculate compounded interest it required a exponent.
Line 203 of the Code is where the error is.
"error C2660: 'System::Math:: Pow' : function does not take 1 arguments"
I hope this clarifies my issue.
Thanks in advance,
Richard
Formulas used:
Simple Interest = Principal * (1 + (Years * Rate))
Compound Interest = Principal * (1 + Rate)^Years
This is the Line of code that is giving me this error:
Code:
// Process data sum = (num1 * (Math::Pow(1 + (num2*.01)),num3));
Code:
#pragma once
namespace InterestCalculator {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ textBoxPrincipal;
protected:
private: System::Windows::Forms::TextBox^ textBoxRate;
private: System::Windows::Forms::TextBox^ textBoxYears;
private: System::Windows::Forms::TextBox^ textBoxSimple;
private: System::Windows::Forms::TextBox^ textBoxCompound;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->textBoxPrincipal = (gcnew System::Windows::Forms::TextBox());
this->textBoxRate = (gcnew System::Windows::Forms::TextBox());
this->textBoxYears = (gcnew System::Windows::Forms::TextBox());
this->textBoxSimple = (gcnew System::Windows::Forms::TextBox());
this->textBoxCompound = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
// textBoxPrincipal
//
this->textBoxPrincipal->Location = System::Drawing::Point(12, 25);
this->textBoxPrincipal->Name = L"textBoxPrincipal";
this->textBoxPrincipal->Size = System::Drawing::Size(100, 20);
this->textBoxPrincipal->TabIndex = 0;
//
// textBoxRate
//
this->textBoxRate->Location = System::Drawing::Point(118, 25);
this->textBoxRate->Name = L"textBoxRate";
this->textBoxRate->Size = System::Drawing::Size(100, 20);
this->textBoxRate->TabIndex = 1;
//
// textBoxYears
//
this->textBoxYears->Location = System::Drawing::Point(224, 25);
this->textBoxYears->Name = L"textBoxYears";
this->textBoxYears->Size = System::Drawing::Size(100, 20);
this->textBoxYears->TabIndex = 2;
//
// textBoxSimple
//
this->textBoxSimple->Location = System::Drawing::Point(158, 51);
this->textBoxSimple->Name = L"textBoxSimple";
this->textBoxSimple->Size = System::Drawing::Size(166, 20);
this->textBoxSimple->TabIndex = 3;
//
// textBoxCompound
//
this->textBoxCompound->Location = System::Drawing::Point(158, 77);
this->textBoxCompound->Name = L"textBoxCompound";
this->textBoxCompound->Size = System::Drawing::Size(166, 20);
this->textBoxCompound->TabIndex = 4;
//
// button1
//
this->button1->Location = System::Drawing::Point(37, 49);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(115, 23);
this->button1->TabIndex = 5;
this->button1->Text = L"Simple Interest";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(37, 78);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(115, 23);
this->button2->TabIndex = 6;
this->button2->Text = L"Compound Interest";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(12, 9);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(47, 13);
this->label1->TabIndex = 7;
this->label1->Text = L"Principal";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(119, 9);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(30, 13);
this->label2->TabIndex = 8;
this->label2->Text = L"Rate";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(223, 9);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(34, 13);
this->label3->TabIndex = 9;
this->label3->Text = L"Years";
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(341, 115);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->textBoxCompound);
this->Controls->Add(this->textBoxSimple);
this->Controls->Add(this->textBoxYears);
this->Controls->Add(this->textBoxRate);
this->Controls->Add(this->textBoxPrincipal);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
// Declare variables num1 Principal, num2 Rate, num3 Years,
double num1, num2, num3, sum;
// Read in Data
Double::TryParse(textBoxPrincipal->Text, num1);
Double::TryParse(textBoxRate->Text, num2);
Double::TryParse(textBoxYears->Text, num3);
// Process data
sum = num1 * (1 + (num3 * (num2*.01)));
// Display results
textBoxSimple->Text = sum.ToString();
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
// Declare variables num1 Principal, num2 Rate, num3 Years,
double num1, num2, num3, sum;
// Read in Data
Double::TryParse(textBoxPrincipal->Text, num1);
Double::TryParse(textBoxRate->Text, num2);
Double::TryParse(textBoxYears->Text, num3);
// Process data
sum = (num1 * (Math::Pow(1 + (num2*.01)),num3));
// Display results
textBoxCompound->Text = sum.ToString();
}
};
}
Comment