I have been trying to figure this out for a little while and I really can't seem to get a good grasp on where I am messing this thing up. I keep getting errors:

Error 2 error C2664: 'input_polar' : cannot convert parameter 2 from 'int' to 'double &'
Error 3 error C2062: type 'void' unexpected

And also my variables within my void statement keep telling me that they are undeclared identifiers C2065.

I kinda understand the first error as the polar input has an integer angle within it, but if I make my angles double then i get this error:

Error 1 error C2664: 'rec_to_polar' : cannot convert parameter 4 from 'double' to 'int &'

I understand the error, just not how to fix it. As for the void unexpected I really do not get that because i told the program I was going to have the void functions at the beginning and I think that is why it is messing up my variables as well.

As for 7 and 8 I have not yet put the function I am going to use in quite yet but they will both deal with the same variables and functions so I would need to finish fixing those errors which in return would correct what I have left to input.

Any help would be greatly appreciated. Thanks in advance.

#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;

void input_rec(double& real, double& imag);
void rec_to_polar(double& real, double& imag, double& mag, int& ang);
void input_polar(double& real, double& imag);
void polar_to_rec(double& real, double& imag, double& mag, int& ang);

//begin main function

const double PI = 4*atan(1.0);

int main()
{

	double reA = 0.0;
	double magA = 0.0;
	double imgA = 0.0;
	double reB = 0.0;
	double magB = 0.0;
	double imgB = 0.0;
	double reC = 0.0;
	double magC = 0.0;
	double imgC = 0.0;
	int angA = 0;
	int angB = 0;
	int angC = 0;
	int choice;

	do
	{
		system("cls");
		
		cout<<"Complex Number A:    Real:    "<<reA<<"Imaginary:    "<<imgA<<"Magnitude:     "<<magA<<"Angle:     "<<angA<<endl;
		cout<<"Complex Number B:    Real:    "<<reB<<"Imaginary:    "<<imgB<<"Magnitude:     "<<magB<<"Angle:     "<<angB<<endl;
		cout<<"Complex Number C:    Real:    "<<reC<<"Imaginary:    "<<imgC<<"Magnitude:     "<<magC<<"Angle:     "<<angC<<endl;
		cout<<endl;

		cout<<"1.    Enter Complex Number A in Rectangular Form."<<endl;
		cout<<"2.    Enter Complex Number A in Polar Form."<<endl;
		cout<<"3.    Enter Complex Number B in Rectangular Form."<<endl;
		cout<<"4.    Enter Complex Number B in Polar Form."<<endl;
		cout<<"5.    Add the two Complex numbers together: C = A + B"<<endl;
		cout<<"6.    Find the Complex Conjugate: C = A*."<<endl;
		cout<<"7.    Multiply the two Complex Numbers: C = AB"<<endl;
		cout<<"8.    Divide the two Complex Numbers"<<endl;
		cout<<"9.    End the Program."<<endl;
		cout<<endl;
		cout<<endl;

		cout<<"Please select an option."<<endl;
		cin>>choice;

		switch(choice)
		{
		case 1:
			input_rec (reA,imgA);
			rec_to_polar (reA,imgA,magA,angA);
			break;

		case 2:
			input_polar (magA,angA);
			polar_to_rec (reA,imgA,magA,angA);
			break;
		case 3:
			input_rec (reB,imgB);
			rec_to_polar(reB,imgB,magB,angB);
			break;
		case 4:
			input_polar (magB,angB);
			rec_to_polar (reB,imgB,magB,angB);
			break;
		case 5:
			reC = (reA+reB);
			imgC = (imgA+imgB);
			rec_to_polar (reC,imgC,magC,angC);
			break;
		case 6:
			reC = reA;
			imgC = imgA*-1;
			rec_to_polar(reC,imgC,magC,angC);
			break;
		case 7:
			cout<<"7"<<endl;
			break;
		case 8: 
			cout<<"8"<<endl;
			break;
		default:
			cout<<"Invalid Choice"<<endl;
		}
		while(choice != 9);

		system("pause");
		return 0;
	}

void input_rec(double& real, double& imag);
{
	cout<<"Input the real part"<<endl;
	cin>>real;
	cout<<"Input the imaginary part"<<endl;
	cin>>imag;
}
void rec_to_polar(double& real, double& imag, double& mag, int& ang);
{
	mag = sqrt(real*real+imag*imag);
	ang = (atan2(imag,real))*(180.0/PI);
}
void input_polar(double& real, double& imag);
{
	cout<<"Enter the Magnitude"<<endl;
	cin>>mag;
	cout<<"Enter the angle"<<endl;
	cin>>ang;
}
void polar_to_rec(double& real, double& imag, double& mag, int& ang);
{
	real = mag*cos(double((ang*PI)/180.0));
	imag = mag*sin(double((ang*PI)/180.0));
}
WaltP commented: I'm impressed! All posts hace CODE Tags and you posted the *exact* error messages! Thank you!!!! +11

Recommended Answers

All 8 Replies

Your declarations and definitions match, which is good. That's not your problem.

I get the same error when I try to compile it, but the message flags line 64. If you have a look at line 64, you'll see that your are using the statement input_polar (magA,angA); . The issue is that angA is defined as an integer. As a result, you call input_polar() as input_polar(double&, int) rather than input_polar(double&, double&) so it's looking for an overloaded function that doesn't exist. I would suggest changing the definition of input_polar() to input_polar(double&, int&) . You have the same issue on line 72.

I also got an error concerning undeclared identifiers in that function. In your input_polar(), what are mag and ang? They don't seem to relate to anything. I think you need to take a look at those variable names. Are you sure you have implemented input_polar() in a manner consistent with your intent? Looking at your variable names in the call relative to your definition, I'm not so sure you have...

To begin with, remove semicolons at lines 100, 107, 112 and 119.

Lines 93 and 94, you closed your switch, but you never closed your do-while loop. It thinks your function definitions are part of your main function because the '}' that you think closes your main() actually doesn't.

mag and ang refer to the magnitude and the angle. removing semicolons at those lines only gave me an additional error. I tryed removing them after all the void statements as well and it didnt do anything.

if I switch the double to an int it will not run the program right because the imaginary must be a double. instead of changing the whole function call on line 64 should i just make that a

input_polar(magA, double(angA))

?

Lines 93 and 94, you closed your switch, but you never closed your do-while loop. It thinks your function definitions are part of your main function because the '}' that you think closes your main() actually doesn't.

I redid those } and here is what i still have:

Error 1 error C2664: 'input_polar' : cannot convert parameter 2 from 'int' to 'double &'

Error 2 error C2664: 'input_polar' : cannot convert parameter 2 from 'int' to 'double &'

Warning 3 warning C4244: '=' : conversion from 'double' to 'int', possible loss of data

Error 4 error C2065: 'mag' : undeclared identifier

Error 5 error C2065: 'ang' : undeclared identifier

You might post the revised code.

if I switch the double to an int it will not run the program right because the imaginary must be a double. instead of changing the whole function call on line 64 should i just make that a

input_polar(magA, double(angA))

I don't think a typecast is the answer here.

Please answer these 2 questions:
1.) Why are you using an imaginary number for a polar angle? An angle is a real number unless you do something really weird.
2.) Why are you trying to use the ang* instead of img* variables then?

I believe I addressed these before when I asked you about your intent...

commented: Thanks +1

I don't think a typecast is the answer here.

Please answer these 2 questions:
1.) Why are you using an imaginary number for a polar angle? An angle is a real number unless you do something really weird.
2.) Why are you trying to use the ang* instead of img* variables then?

I believe I addressed these before when I asked you about your intent...

I got it working from a little help from a friend. Thanks alot tho I didnt have to change much at all. The assignment was over complex numbers so that is why I had to use the imaginary.

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.