hello every one ,
i am working on this code for a week , but i have a problem that every time i try to debug it i receive many errors i can't understand them
here is my code

/*
Simple program to compute the two possible roots of a quadratic equation.
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <ostream>
using namespace std;
#define mR00t 20

struct cmplxNumber{
	double dReal, dImaginary;
} ;

bool ComputeRoots( double dCoefA, double dCoefB, double dCoefC, 
				  cmplxNumber & Root1, cmplxNumber & Root2);

ostream & PrintComplex( ostream & outDevice, cmplxNumber Root );

int main()
{
	// Need some variable storage for parameters
	double dCoefA = 0.0, dCoefB = 0.0, dCoefC = 0.0;
	cmplxNumber R00t1 [mR00t] , R00t2 [mR00t] ;
	char choice ;
	int count = 0 ;
	int dataReadedFromFile = 0;
	do
	{
		cout << " please , enter 1 for reading data from file " << endl ;
		cout  << " pleasse , enter 2 for displaying the stored resoults " << endl ;
		cout << " please , enter 3 for computing the complex numbers " << endl ;
		cout << " please, enter 4 for compute the roots " << endl ;
		cout << " please enter 5 to exit this program " << endl ;
		cin >> choice ;

		if ( choice == '1' )
		{ 
			ifstream rawData ;
			rawData.open ("RAW.DATA.txt") ;
			if (  ! rawData.good () )
			{
				cout  << " sorry .....  the program can't open this file " << endl ;
				system ("pause") ;
				break ;
			}
			else 
			{
				cout << " the program reading the data from the file now " << endl ;
				do 
				{
					rawData>> dCoefA >> dCoefB >>dCoefC;
					cout << dCoefA << "  " << dCoefB << "  " << dCoefC << endl ;
					cmplxNumber Root1, Root2 ;
					ComputeRoots( dCoefA, dCoefB, dCoefC, Root2, Root1 );
					cout << "\n\nThe first root is " << Root1.dReal;
					if( Root1.dImaginary < 0.0 ) {
						cout << " - " << abs(Root1.dImaginary) << " j" << endl;
					}
					else if( Root1.dImaginary > 0.0 ) {
						cout << " + " << Root1.dImaginary << " j" << endl; 
					}
					else 
						cout << endl;

					cout << "\n\nThe second root is ";
					PrintComplex( cout, Root2 );
					R00t1[count] = Root1 ;
					R00t2[count] = Root2 ;
					count ++ ;
				} while ( ! rawData.eof () && (count < mR00t)  ) ;
				cout << " the end of the data " << endl ;
				system ("pause") ;
				continue ;
			}
			continue ;
		}
		if (choice == '2')
		{
			cout << " the program will display the stored resoults " << endl ;
			
			dataReadedFromFile = count ;
			cout << " the program readed "<< dataReadedFromFile << " from the file " << endl ;
			count = 0 ;
			do 
			{
				cout << " the first root is "  ;
				PrintComplex( cout, R00t1[count] );
				cout << endl ;
				cout << " the second root is  "  ;
				PrintComplex( cout, R00t2[count] );
				cout << endl ;
				count ++ ;

			}while ( count < dataReadedFromFile ) ;
			system ("pause") ;
			continue ;
		}
		if ( choice == '3' )
		{
			cout << "the program will compute complex nubers and display the average  " << endl ;
			ifstream DATA2 ;
			DATA2.open ("RAW.DATA2.txt");
			ofstream REPORT ;
			REPORT.open ("REPORT.txt") ;
			if ( ! DATA2.good ()  )
			{
				cout << " the program can't open the file " << endl ;
				break ;
			}
			else if (! REPORT.good () )
			{
				cout << " the program can't open the output file " << endl ;
				break ;
			}
			else 
			{

				cmplxNumber real , imaginary ;
				real.dReal = 0.0 ;
				imaginary.dImaginary = 0.0 ;
				double sum = 0.0  ;
				double sum2 = 0.0;
				double aver = 0.0 ;
				double Rreal[40], Iimaginary[40] ;
				cout << " the program is reading the data from the file " << endl ;
				count = 0 ;
				cout <<  endl ;

				do 
				{
					DATA2 >> real.dReal >> imaginary.dImaginary ;
					Rreal[count] = real.dReal ;
					Iimaginary[count] = imaginary.dImaginary ;
					sum = real.dReal + imaginary.dImaginary ;
					cout << "the real point is " << real.dReal << endl ;
					cout << "the imaginary point is " << imaginary.dImaginary << endl ;
					cout << " the total for them is " << sum << endl ;
					REPORT << " the total is  " << sum << endl ;
					sum2 =  (sum2 + sum ) ;
					count ++ ;
					cout << endl;

				} while ( ! DATA2.eof () && count < 40);
				cout << count << endl ;
				aver = (sum2 / count) ;
				cout << " the total for all the sums is " << sum2 << endl ;
				cout << " the average for the total is  " << sum2 <<" / " << count  ; 
				cout << "  =  " << aver << endl ;
				REPORT << "the average for the points total is  " << sum2 << " / "  << count ;
				REPORT << "  =  " <<aver << endl ;
				DATA2.close () ;
				REPORT.close () ;

			}
			system ("pause") ;
			continue ;
		}
		if (choice == '4')
		{
			count = 0 ;
			cmplxNumber A , B ,C;
			do 
			{
			A = R00t1[count] ;
			B = R00t2[count] ;
			
			C = add (A + B );
			cout << " the resoult of adding the two roots is " ;
			PrintComplex( cout, C );
			C = (A - B) ;
			cout << endl;
			cout << " the resoult of subtracting the first root from the second root is  " ;
			PrintComplex( cout, C );
			cout << endl ;
			
			count ++ ;

			} while ( count < dataReadedFromFile ) ; 

		}
		if ( choice == '5')
		{
			cout << " the program will exit " << endl ;
			system ("pause");
			break ;
		}
	} while ( mR00t == 20 );
}
bool ComputeRoots( double dCoefA, double dCoefB, double dCoefC, 
				  cmplxNumber & Root1, cmplxNumber & Root2)
{
	double dInter1, dInter2;
	dInter1 = dCoefB * dCoefB;  // get the square of B
	dInter2 = 4.0 * dCoefA * dCoefC;
	if(dInter1 < dInter2 ) {
		Root1.dImaginary = pow(abs(dInter1 - dInter2), 0.5)/ (2.0 * dCoefA);
		Root2.dImaginary = -pow(abs(dInter1 - dInter2), 0.5)/ (2.0 * dCoefA);
		Root1.dReal = Root2.dReal = -dCoefB / (2.0 * dCoefA);
	} else {
		Root1.dReal = (-dCoefB + pow(dInter1 - dInter2, 0.5))/ (2.0 * dCoefA);
		Root2.dReal = (-dCoefB - pow(dInter1 - dInter2, 0.5))/ (2.0 * dCoefA);
		Root1.dImaginary = Root2.dImaginary = 0.0;
	}
	return true;
}

// declaration of function using 'things' from the stream devices is 
//  fairly exacting.  MUST use references to the device variables.
ostream & PrintComplex( ostream & outDevice, cmplxNumber Root )
{
	outDevice << Root.dReal;
	if( Root.dImaginary < 0.0 ) {
		outDevice << " - " << abs(Root.dImaginary) << " j" << endl;
	}
	else if( Root.dImaginary > 0.0 ) {
		outDevice << " + " << Root.dImaginary << " j" << endl; 
	}
	else 
		cout << endl;
	return outDevice;
}

the errors are

Error	1	error C2784: 'std::_String_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_iterator<_Elem,_Traits,_Alloc>' from 'cmplxNumber'	c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp	170
Error	2	error C2784: 'std::_String_const_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_const_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_const_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_const_iterator<_Elem,_Traits,_Alloc>' from 'cmplxNumber'	c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp	170
Error	3	error C2784: 'std::reverse_iterator<_RanIt> std::operator +(_Diff,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'cmplxNumber'	c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp	170
Error	4	error C2784: 'std::_Revranit<_RanIt,_Base> std::operator +(_Diff,const std::_Revranit<_RanIt,_Base> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'cmplxNumber'	c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp	170
Error	5	error C2676: binary '+' : 'cmplxNumber' does not define this operator or a conversion to a type acceptable to the predefined operator	c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp	170
Error	6	error C3861: 'add': identifier not found	c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp	170
Error	7	error C2784: 'reverse_iterator<_RanIt>::difference_type std::operator -(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'cmplxNumber'	c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp	173
Error	8	error C2784: '_Base1::difference_type std::operator -(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'cmplxNumber'	c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp	173
Error	9	error C2676: binary '-' : 'cmplxNumber' does not define this operator or a conversion to a type acceptable to the predefined operator	c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp	173

Edited 5 Years Ago by mic_mic: n/a

The problem is that your compiler doesn't know how to add/subtract complex numbers using operators +/-

A simple solution is to define two functions for these operations...

//...

cmplxNumber add_cmplx(const cmplxNumber & c1, const cmplxNumber & c2)
{
    //...
}

cmplxNumber sub_cmplx(const cmplxNumber & c1, const cmplxNumber & c2)
{
    //...
}

//...

...and then use them like this:

//...

C = add_cmplx(A, B);

//...

C = sub_cmplx(A, B);

//...

Edited 5 Years Ago by m4ster_r0shi: n/a

thank you "m4Ster" for helping .
but now i received 3 errors

Error	1	error LNK2019: unresolved external symbol "struct cmplxNumber __cdecl sub_cmplx(struct cmplxNumber const &,struct cmplxNumber const &)" (?sub_cmplx@@YA?AUcmplxNumber@@ABU1@0@Z) referenced in function _main	HW3_Shokery.obj
Error	2	error LNK2019: unresolved external symbol "struct cmplxNumber __cdecl add_cmplx(struct cmplxNumber const &,struct cmplxNumber const &)" (?add_cmplx@@YA?AUcmplxNumber@@ABU1@0@Z) referenced in function _main	HW3_Shokery.obj
Error	3	fatal error LNK1120: 2 unresolved externals	C:\Users\michael\Documents\Visual Studio 2008\Projects\HW 3 _ Shokery\Debug\HW 3 _ Shokery.exe

Edited 5 Years Ago by mic_mic: n/a

I know people are going to call me petty, but a point here. Why have you got a structure in an object oriented architecture. I tend to find that if you stick to the basic rules you get less problems down the line. If you have something that you need to pass form one object to another then you haven't designed it true objectivity in mind if you need a structure. Try rethinking your design [maybe just as an exercise if it's a vital piece of code that you can afford to re build]. If everything is object oriented it's a lot easier to keep track of..

This means that you just declared your functions, i.e. you just added these lines to your code:

cmplxNumber add_cmplx(const cmplxNumber & c1, const cmplxNumber & c2);
cmplxNumber sub_cmplx(const cmplxNumber & c1, const cmplxNumber & c2);

You have to define them too (i.e. tell the compiler exactly how they work). Just like you do with PrintComplex.

This is its declaration:

ostream & PrintComplex( ostream & outDevice, cmplxNumber Root );

And this is its definition:

ostream & PrintComplex( ostream & outDevice, cmplxNumber Root )
{
	outDevice << Root.dReal;
	if( Root.dImaginary < 0.0 ) {
		outDevice << " - " << abs(Root.dImaginary) << " j" << endl;
	}
	else if( Root.dImaginary > 0.0 ) {
		outDevice << " + " << Root.dImaginary << " j" << endl; 
	}
	else 
		cout << endl;
	return outDevice;
}

i did

cmplxNumber add_cmplx(const cmplxNumber & c1, const cmplxNumber & c2);
{
	C = add_cmplx(A, B);
};
cmplxNumber sub_cmplx(const cmplxNumber & c1, const cmplxNumber & c2) ;
{
	C = sub_cmplx(A, B);
};

and i received

Error	1	error C2447: '{' : missing function header (old-style formal list?)	c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp	230
Error	2	error C2447: '{' : missing function header (old-style formal list?)	c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp	234

it is my , but i just start studying c++ 2 months ago.
it's my homework , and the teacher was helping me , but he is far a way now and it due by tomorrow .
thank you

Edited 5 Years Ago by mic_mic: n/a

it due by tomorrow

Well, you'd better hurry and check out the links I gave you!

I'll give you one last hint:

cmplxNumber add_cmplx(const cmplxNumber & c1, const cmplxNumber & c2)
{
    // create a complex number variable (let's call it temp) 
    
    // set temp's real part to 
    // c1's real part plus c2's real part
    
    // set temp's imaginary part to 
    // c1's imaginary part plus c2's imaginary part
    
    // return temp;
}

Edited 5 Years Ago by m4ster_r0shi: n/a

thank you so much " m4ster"

cmplxNumber add_cmplx(const cmplxNumber & B, const cmplxNumber & A)
{
	
	temp.dReal = A.dReal + B.dReal;
	temp.dImaginary = A.dImaginary + B.dImaginary ;
	return temp ;
	
};
cmplxNumber sub_cmplx(const cmplxNumber & B, const cmplxNumber & A ) 
{
	
	temp2.dReal = A.dReal - B.dReal ;
	temp2.dImaginary = A.dImaginary - B.dImaginary ;
	
	return temp2 ;
};

now i don't have any errors . just a logical error all the results are zero .

Edited 5 Years Ago by mic_mic: n/a

if (choice == '4')
		{
			cmplxNumber A , B ;
			count = 0 ;
			do 
			{
			A = R00t1[count] ;
			B = R00t2[count] ;
			cout << " the first root is " << endl ;
			PrintComplex( cout, A );
			cout << " the second root is " << endl ;
			PrintComplex( cout, B );
			cout << " the resoult of adding the two roots is " ;
			temp =  add_cmplx(A,B);
			PrintComplex( cout, temp );
			cout << " the resoult of subtracting the first root from the second root is  " ;
			temp2 = sub_cmplx ( A , B ) ;
			PrintComplex( cout, temp2 );
			cout <<  endl ;
			count ++ ;
			} while ( count < dataReadedFromFile ) ;
if (choice == '4')
		{
			cmplxNumber A , B ;
			count = 0 ;
			do 
			{
			A = R00t1[count] ;
			B = R00t2[count] ;
			cout << " the first root is "  ;
			PrintComplex( cout, A );
			cout << endl ;
			cout << " the second root is "  ;
			PrintComplex( cout, B );
			cout << endl ;
			cout << " the resoult of adding the two roots is " ;
			temp =  add_cmplx(A,B);
			PrintComplex( cout, temp );
			cout << " the resoult of subtracting the first root from the second root is  " ;
			temp2 = sub_cmplx ( A , B ) ;
			PrintComplex( cout, temp2 );
			cout <<  endl ;
			count ++ ;
			} while ( count < dataReadedFromFile ) ;
This question has already been answered. Start a new discussion instead.