By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,145 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

Help in syntax void function

P: 11
(Regula falsi metod. To calculate the root using 4 iterations)
I need the user to pick from problem a, b or c wherein every problem has different initial guesses.ex( prob. a Xd=1 Xu=2, prob. b Xd=2 Xu=3)
same process for all problems. And also i want to show all the values of Xd,Xu,Xr,d,u,r for the 4 iterations in tabular form.What i have done so far is this:

void falsi(double& fd, double& fu, double& fr, double d, double u, double r)
{
fd=sin(d)+cos(1+d*d)-1;
fu=sin(u)+cos(1+u*u)-1;
r=((u*fd - d*fu) / (fd - fu));
fr=sin(r)+cos(1+r*r)-1;
}

void eq(int x, int y)
{
d=1;
u=2;
cout<<"The value of Xd=1 and Xu=2\n";
for (i=4;i<5;i++)
{
falsi(fd,fu,fr,d,u,r)
if (fr>0 && fd>0)
{
r=d;
else
r=u;
}
cout<<fd<<fu<<fr<<d<<u<<r;
}

int main
{
cout<<"choose letter a, b, or c";
cin<<z; // is this correct??
if (z==a)
{
void eq(1,2);
if(z==b)
{
void eq(2,3);
else
void eq(1,4);
}
}

// Is this correct?
Btw, where can i download MSdev C++ version 5.0?
Aug 12 '07 #1
Share this Question
Share on Google+
3 Replies


ilikepython
Expert 100+
P: 844
(Regula falsi metod. To calculate the root using 4 iterations)
I need the user to pick from problem a, b or c wherein every problem has different initial guesses.ex( prob. a Xd=1 Xu=2, prob. b Xd=2 Xu=3)
same process for all problems. And also i want to show all the values of Xd,Xu,Xr,d,u,r for the 4 iterations in tabular form.What i have done so far is this:

void falsi(double& fd, double& fu, double& fr, double d, double u, double r)
{
fd=sin(d)+cos(1+d*d)-1;
fu=sin(u)+cos(1+u*u)-1;
r=((u*fd - d*fu) / (fd - fu));
fr=sin(r)+cos(1+r*r)-1;
}

void eq(int x, int y)
{
d=1;
u=2;
cout<<"The value of Xd=1 and Xu=2\n";
for (i=4;i<5;i++)
{
falsi(fd,fu,fr,d,u,r)
if (fr>0 && fd>0)
{
r=d;
else
r=u;
}
cout<<fd<<fu<<fr<<d<<u<<r;
}

int main
{
cout<<"choose letter a, b, or c";
cin<<z; // is this correct??
if (z==a)
{
void eq(1,2);
if(z==b)
{
void eq(2,3);
else
void eq(1,4);
}
}

// Is this correct?
Btw, where can i download MSdev C++ version 5.0?
You have some syntax errors.
Expand|Select|Wrap|Line Numbers
  1. void eq(int x, int y)
  2. {
  3.     d=1;
  4.     u=2;
  5.     cout<<"The value of Xd=1 and Xu=2\n";
  6.     for (i=4;i<5;i++)
  7.     {
  8.         falsi(fd,fu,fr,d,u,r)
  9.         if (fr>0 && fd>0)
  10.         {
  11.             r=d;
  12.         else
  13.             r=u;
  14. }
  15. cout<<fd<<fu<<fr<<d<<u<<r;
  16. }
You call falsi with fd, fu, fr, u, and r, but you never declared fd, fu ,fr, or r. Also, you never use x and y which are passed into the function.
Expand|Select|Wrap|Line Numbers
  1. if (fr>0 && fd>0)
  2. {
  3.     r=d;
  4. else
  5.         r=u;
  6. }
The brace on that if is wrong. It should be like this:
Expand|Select|Wrap|Line Numbers
  1. if (fr > 0 && fd > 0)
  2. {
  3.     r = d;
  4. }
  5. else
  6. {
  7.     r = u;
  8. }
  9.  
You also did that in main.
Expand|Select|Wrap|Line Numbers
  1. int main
  2. {
  3.     cout<<"choose letter a, b, or c";
  4.     cin<<z;    // is this correct??
  5.     if (z==a)
  6.     {
  7.         void eq(1,2);
  8.     if(z==b)
  9.     {
  10.         void eq(2,3);
  11.     else
  12.         void eq(1,4);
  13. }
  14. }
You never declared 'z' when you use it with cin. Also, you are checking z with the variable 'a'. You want to check it against the value 'a'. Also, you are calling your functions wrong. Delete the void before the call.
Expand|Select|Wrap|Line Numbers
  1. int main
  2. {
  3.     char z;
  4.     cout<<"choose letter a, b, or c";
  5.     cin<<z;    // is this correct??
  6.     if (z=='a')
  7.     {
  8.         eq(1,2);
  9.     }
  10.     else if (z=='b')
  11.     {
  12.         eq(2,3);
  13.     }
  14.     else
  15.     {
  16.         void eq(1,4);
  17.     }
  18. }
  19. }
Hope that helps.

PS And please put your code in code tags, it makes it easier to read.
Aug 12 '07 #2

P: 11
thx so much phython! sorry i'm just new here and i dont know how to create tags..
what about void(int x,int y)? i didn't quite understand whats wrong with it..can you clear it up more?thx so much again!!

btw, will this program work?
Aug 12 '07 #3

ilikepython
Expert 100+
P: 844
thx so much phython! sorry i'm just new here and i dont know how to create tags..
what about void(int x,int y)? i didn't quite understand whats wrong with it..can you clear it up more?thx so much again!!

btw, will this program work?
The code tags are just [ c o d e = c p p ] [ / c o d e ] without the spaces.

Your function takes two integers, x, and y. You never use them in the function. What are you trying to do?
Aug 12 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.