# Help for c++ code error.....

Page 1 of 1

## 1 Replies - 2230 Views - Last Post: 02 May 2009 - 01:16 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=102966&amp;s=865decb919e8c5a670fe7fd006fa7055&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 hamza elhamrawy

Reputation: 0
• Posts: 1
• Joined: 02-May 09

# Help for c++ code error.....

Posted 02 May 2009 - 01:10 PM

hi,
Find areal root of equation cosx=3x-1 correct to 3 desimal places using iteration method.

```#include<iostream.h>
#include<math.h>
#include<conio.h>
#define EPS 0.00005
#define F(X) (cos*x +1)/3
#define f(x) cos*x -3*x +1
void ITER();
void main()
{
cout << "\n\t Solution by ITERATION method \n" << endl;
cout <<"\n\t Eqution is:";
cout <<"\n\t\t\t\t cos*x +3*x +1=0\n\n";
ITER();
getch();
}
void ITER()
{
float x1,x2,x0,f0,f1,f2,error;
int i=0,n;
for(x1=1;;x1++)
{
f1=f(x1);
if(f1>0)
break;
}
for(x0=x1-1;;x0--)
{
f0=f(x0);
if(f0<0)
break;
}
x2=(x0=x1)/2;
cout <<"Enter the number of uterations:";
cin >>"%d",&n;
cout <<"\n\n\t\t The 1 approximation to the root is: %f",x2;
for(;i<n-1;i++)
{
f2=f(x2);
cout <<"\n\n\t\tThe %d approximation to the root is: %f",i+2,f2;
x2=f(x2);
error=fabs(f2-f1);
if(error<EPS)
break;
f1=f2;
}
if(error>EPS)
cout <<"\n\n\t NOTE:- The number of iterations are not sufficient.";
cout <<"\n\n\n\t\t---------------------------------";
cout <<"\n\t\t\t The root is %.4f",f2;
cout <<"\n\t\t\t----------------------------------";
}

```

When it was implemented on microsoft visual c++ Gave me four errors and one warning

``` error C2296: '*' : illegal, left operand has type 'double (__cdecl *)(double)'
error C2296: '*' : illegal, left operand has type 'double (__cdecl *)(double)'
error C2296: '*' : illegal, left operand has type 'double (__cdecl *)(double)'
error C2296: '*' : illegal, left operand has type 'double (__cdecl *)(double)'
warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
```

What do I do?
Thank you very much,

Is This A Good Question/Topic? 0

## Replies To: Help for c++ code error.....

### #2 KYA

• Wubba lubba dub dub!

Reputation: 3202
• Posts: 19,232
• Joined: 14-September 07

## Re: Help for c++ code error.....

Posted 02 May 2009 - 01:16 PM

You need to use cmath's cos, which is cos(value) not cos* value

I don't even know what cos*x would give you. cos of nothing is undefined