Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,485 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,735 people online right now. Registration is fast and FREE... Join Now!




Complex numbers

 
Reply to this topicStart new topic

Complex numbers

DMurdoc
5 Mar, 2008 - 07:10 AM
Post #1

New D.I.C Head
*

Joined: 5 Mar, 2008
Posts: 1

I am having trouble compiling my program after I input the string for the magnitude.
I dont know if there is something I am missing in the string or not, and when I compile I get this error message:

complex_experiment.cpp: In function âint main()â:
complex_experiment.cpp:28: error: expected primary-expression before â[â token

Here is my code. I hope someone can help me.

#include<iostream>
#include<complex>
using std::complex;
using namespace std;
int main()
{
double real xa, imag(ya);
double xb, yb;
complex<double> number(real, imag);
cout << "Enter the real and imaginary parts of a complex number: \n";
cin >> xa >> ya;
cout << "Enter the parts for another complex number: \n";
cin >> xb >> yb;
while (xa >= xb)
{
cout << "Coordinate 1 = " << xa << ", " << ya << "\n";
cout << "Co. 2 = " << xb << ", " << yb << "\n";
cout << "Co. 1 + Co. 2 = " << xa + xb << ", " << ya + yb << "\n";
cout << "Co. 1 - Co. 2 = " << xa - xb << ", " << ya - yb << "\n";
cout << "Co. 1 * Co. 2 = " << xa * xb << ", " << ya * yb << "\n";
cout << "Co. 1 / Co. 2 = " << xa / xb << ", " << ya / yb << "\n";
cout << "Co. 1 real part = " << xa << "\n";
cout << "Co. 1 imaginary part = " << ya << "\n";
cout << "Magnitude of Co. 1 = " << abs([xa, ya]) << "\n";
}
return 0;
}


I am trying to do: Call real() and imag() ON a complex number, each gives a result.
PASS a complex number to the abs() function, it returns the magnitude.

I am completely confused as to what to do.
Any help would be greatly appreciated.
User is offlineProfile CardPM
+Quote Post

MorphiusFaydal
RE: Complex Numbers
5 Mar, 2008 - 07:15 AM
Post #2

D.I.C Lover
Group Icon

Joined: 12 May, 2005
Posts: 1,105



Thanked: 8 times
Expert In: Hardware, Networking

My Contributions
cout << "Magnitude of Co. 1 = " << abs([xa, ya]) << "\n"; is the line the error message is referring to. What are you trying to accomplish with the [] ? You don't need them.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 07:14PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month