Hi, I got the error
C2064: term does not evaluate to a function taking 2 arguments
The error is in line 76, help would be great.

Here is my code:

#pragma once



namespace ValestromsCalculator {

	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 GCF
	/// </summary>
	public ref class GCF : public System::Windows::Forms::Form
	{
	public:
		GCF(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~GCF()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::TextBox^  textBox1;

	private: System::Windows::Forms::TextBox^  textBox3;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Label^  label2;

	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::Label^  label4;
	private: System::Windows::Forms::Button^  button2;
	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;
		// My Variables
	private:
		int gcf1;
		int gcf2;
		int gcf;

#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 Gcffunction() {
			if (gcf1 % gcf2 == 0){
				gcf = gcf2;
			}
			else{
				return gcf(gcf2, gcf1 % gcf2);
			
			}
		}

		void InitializeComponent(void)
		{
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->textBox3 = (gcnew System::Windows::Forms::TextBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->label4 = (gcnew System::Windows::Forms::Label());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(100, 36);
			this->textBox1->Name = L"textBox1";
			this->textBox1->Size = System::Drawing::Size(39, 20);
			this->textBox1->TabIndex = 0;
			this->textBox1->TextChanged += gcnew System::EventHandler(this, &GCF::textBox1_TextChanged);
			// 
			// textBox3
			// 
			this->textBox3->Location = System::Drawing::Point(145, 36);
			this->textBox3->Name = L"textBox3";
			this->textBox3->Size = System::Drawing::Size(39, 20);
			this->textBox3->TabIndex = 2;
			this->textBox3->TextChanged += gcnew System::EventHandler(this, &GCF::textBox3_TextChanged_1);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(108, 20);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(23, 13);
			this->label1->TabIndex = 3;
			this->label1->Text = L"# 1";
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(153, 20);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(23, 13);
			this->label2->TabIndex = 4;
			this->label2->Text = L"# 2";
			this->label2->Click += gcnew System::EventHandler(this, &GCF::label2_Click);
			// 
			// button1
			// 
			this->button1->BackColor = System::Drawing::Color::Black;
			this->button1->ForeColor = System::Drawing::Color::DarkRed;
			this->button1->Location = System::Drawing::Point(78, 71);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(129, 54);
			this->button1->TabIndex = 6;
			this->button1->Text = L"Find The GCF!";
			this->button1->UseVisualStyleBackColor = false;
			this->button1->Click += gcnew System::EventHandler(this, &GCF::button1_Click);
			// 
			// label4
			// 
			this->label4->AutoSize = true;
			this->label4->Location = System::Drawing::Point(142, 189);
			this->label4->Name = L"label4";
			this->label4->Size = System::Drawing::Size(0, 13);
			this->label4->TabIndex = 7;
			this->label4->TextAlign = System::Drawing::ContentAlignment::TopCenter;
			// 
			// button2
			// 
			this->button2->BackColor = System::Drawing::Color::Black;
			this->button2->ForeColor = System::Drawing::Color::DarkRed;
			this->button2->Location = System::Drawing::Point(85, 212);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(114, 38);
			this->button2->TabIndex = 8;
			this->button2->Text = L"Exit";
			this->button2->UseVisualStyleBackColor = false;
			this->button2->Click += gcnew System::EventHandler(this, &GCF::button2_Click);
			// 
			// GCF
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 262);
			this->Controls->Add(this->button2);
			this->Controls->Add(this->label4);
			this->Controls->Add(this->button1);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->textBox3);
			this->Controls->Add(this->textBox1);
			this->Name = L"GCF";
			this->Opacity = 0.85;
			this->Text = L"GCF";
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void label2_Click(System::Object^  sender, System::EventArgs^  e) {
			 }
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			 Gcffunction();


		 }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
			 Application::Exit();
			
		 }
private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
			 int gcf1;
			 if(Int32::TryParse(textBox1->Text, gcf1))
				 gcf1 = Convert::ToInt32(textBox1->Text);
			 else
			 textBox1->Text = Convert::ToString(gcf1);
		 }
		 
private: System::Void textBox3_TextChanged_1(System::Object^  sender, System::EventArgs^  e) {
			  int gcf2;
			 if(Int32::TryParse(textBox3->Text, gcf2))
				 gcf2 = Convert::ToInt32(textBox3->Text);
			 else
			 textBox3->Text = Convert::ToString(gcf2);
		 }
};
}

This line, a few lines before line 76 in the listing above:

return gcf(gcf2, gcf1 % gcf2);

I suspect that this is the erroneous line. Given that gcf, gcf1 and gcf 2 are all int, this doesn't make a lot of sense to me. I'm not familiar with .NET (and I'm sure pseudorandom21 will be along in a moment to down-rep this post to punish me for not knowing any .NET :) ) so maybe it's some notation I'm not clear on, but what are you trying to return? Are you trying to set the value of gcf and then return it?

I concur, the error I see is return gcf(gcf2, gcf1 % gcf2); I can't really work out what you're trying to do with this line eitherin context of your application. The only thing I can think of, is that you're trying to use gcf as a pointer to some method, but this is an incredibly bad way to do things, in my opinion.

I concur, the error I see is return gcf(gcf2, gcf1 % gcf2); I can't really work out what you're trying to do with this line eitherin context of your application. The only thing I can think of, is that you're trying to use gcf as a pointer to some method, but this is an incredibly bad way to do things, in my opinion.

I kinda got lost on how to do it. This whole function, and yes line 76 was the return gcf line. That code is how it showed up in my c++ book, but I haven't figured out how to port the same code/idea to .NET

Please tell me what you're attempting to do, because from looking at that, it appears you're attempting to call a function that has been stored as a pointer into the int variable (ints can store pointers and be used as function pointers but in most cases this is a bad idea) There's really no .net equivalent, so I'm not sure what you're trying.

Explain what you want this line to do and I will show you how to do it :)

Please tell me what you're attempting to do, because from looking at that, it appears you're attempting to call a function that has been stored as a pointer into the int variable (ints can store pointers and be used as function pointers but in most cases this is a bad idea) There's really no .net equivalent, so I'm not sure what you're trying.

Explain what you want this line to do and I will show you how to do it :)

I'm trying to get the input from the user from the two text boxes, then use a function to calculate the GCF (or Greatest Common Factor) of those two numbers. I'm not sure how to do this in .NET, I swiped this code from my console c++ book, but I couldn't find a solution to get it to work with this program.

In summary:
Get input from 2 boxes gcf1 and gcf2, calculate the GCF, then store in under the integer variable gcf

I presume that you intend the function named Gcffunction to accept two int values and return an int that is the greatest common factor. Your function is a recursive function, which calls itself over and over until the answer is reached, but you've made a simple typo in it.

As it is, your function looks a little wobbly. Here is a working function that accepts two integers and returns an integer that is the greatest common factor.

int Gcffunction(int a, int b)
{
	if(b == 0)
	{
	        return a;
	}
	else
	{
		return Gcffunction(b, a % b);
	}
}

You can see that it's very similar to your original Gcffunction, but this one now calls itself recusrsively (you wrote return gcf(gcf2, gcf1 % gcf2); where I think you should have written return Gcffunction(gcf2, gcf1 % gcf2);)

This function needs to be passed the two values, and returns an int. I note that your original function didn't get passed the values, but instead took them from the class in which it lives, and your code seems a little confused about whether the Gcffunction returns anything (the function returns void i.e. there is no return, but them you try to return something anyway) so you need to decide exactly what you want the inputs and outputs to be.

Hope that's clear now - it was a simple typo and now that I've rambled on about it I hope you've got enough to fix it all.

commented: Thanks. Didn't have time to log in last night :) +8

I presume that you intend the function named Gcffunction to accept two int values and return an int that is the greatest common factor. Your function is a recursive function, which calls itself over and over until the answer is reached, but you've made a simple typo in it.

As it is, your function looks a little wobbly. Here is a working function that accepts two integers and returns an integer that is the greatest common factor.

int Gcffunction(int a, int b)
{
	if(b == 0)
	{
	        return a;
	}
	else
	{
		return Gcffunction(b, a % b);
	}
}

You can see that it's very similar to your original Gcffunction, but this one now calls itself recusrsively (you wrote return gcf(gcf2, gcf1 % gcf2); where I think you should have written return Gcffunction(gcf2, gcf1 % gcf2);)

This function needs to be passed the two values, and returns an int. I note that your original function didn't get passed the values, but instead took them from the class in which it lives, and your code seems a little confused about whether the Gcffunction returns anything (the function returns void i.e. there is no return, but them you try to return something anyway) so you need to decide exactly what you want the inputs and outputs to be.

Hope that's clear now - it was a simple typo and now that I've rambled on about it I hope you've got enough to fix it all.

Excited to try this out, thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.