error in the line 25, A Statement!

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 907 Views - Last Post: 08 October 2013 - 10:26 PM Rate Topic: -----

#1 siri86  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 07-October 13

error in the line 25, A Statement!

Posted 07 October 2013 - 10:03 PM

hey everyone, have a problem with the following program:
#include <math.h>
#include <stdio.h>

#define PI  3.1415926535897932384626433832795
#define N   30

int main()
{
  // Delvare two arrays to hold the coordinates of initial data points
  double x[N], y[N],(x2);
  int i;

  // Generate the points
  double xx = PI/2;
  double step = 2 * PI / (N - 1);

  for ( i = 0; i < N; ++i, xx += step)
  {
    double x2=xx+sin(xx);   // vary x spacing
    x[i] = x2;
    y[i] = sin(x2)/x2;
  }

  // Initialize the regression approximation routine with known data points
     A.getValue(N, x, y, 3);

     // Interrogate the regression function to find approximated values
  int N_out =50;
  xx = PI/2 ;
  step = 2 * PI / (N_out - 1);

  printf("\nx, exact, discrete_3,  discrete_5,  discrete_10");

  for ( i = 0; i < N_out; ++i, xx += step)
  {
    double x2=xx+sin(xx);
    printf("\n%.4lf, %.6lf, %.6lf, %.6lf, %.6lf", x2, sin(x2)/x2, A.getValue(x2));
  }
  return 0;


This post has been edited by Skydiver: 07 October 2013 - 10:04 PM
Reason for edit:: Put code in code tags. Learn to follow instructions.


Is This A Good Question/Topic? 0
  • +

Replies To: error in the line 25, A Statement!

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3163
  • View blog
  • Posts: 9,556
  • Joined: 05-May 12

Re: error in the line 25, A Statement!

Posted 07 October 2013 - 10:08 PM

What is the error that you are getting?

Perhaps if you included "discrete.h" like it did in http://www.codecogs....on/discrete.php you would have more success.
Was This Post Helpful? 1
  • +
  • -

#3 siri86  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 07-October 13

Re: error in the line 25, A Statement!

Posted 07 October 2013 - 10:34 PM

the error is: request for member 'getValue' in something not a structur or union. in line 25 and 39 where getValue is appeared.
Was This Post Helpful? 0
  • +
  • -

#4 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: error in the line 25, A Statement!

Posted 07 October 2013 - 11:02 PM

What is A?

You have not defined it anywhere and it's not defined in the standard library. Define the A structure.

Lets say that A is defined. That is still the incorrect syntax. You must first create an object for the function to operate on. Also, getValue() is not defined. In C you can access the members of a struct with . (dot) notation. i.e. A.value = 10
Was This Post Helpful? 1
  • +
  • -

#5 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3163
  • View blog
  • Posts: 9,556
  • Joined: 05-May 12

Re: error in the line 25, A Statement!

Posted 08 October 2013 - 05:42 AM

After missing the #include, it also looks like he missed the declaration of variables A, B, and C:
  // Initialize the regression approximation routine with known data points
  Maths::Regression::Discrete A(N, x, y, 3);
  Maths::Regression::Discrete B(N, x, y, 5);
  Maths::Regression::Discrete C(N, x, y, 10);


Was This Post Helpful? 1
  • +
  • -

#6 siri86  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 07-October 13

Re: error in the line 25, A Statement!

Posted 08 October 2013 - 04:01 PM

View PostSkydiver, on 08 October 2013 - 05:42 AM, said:

After missing the #include, it also looks like he missed the declaration of variables A, B, and C:
  // Initialize the regression approximation routine with known data points
  Maths::Regression::Discrete A(N, x, y, 3);
  Maths::Regression::Discrete B(N, x, y, 5);
  Maths::Regression::Discrete C(N, x, y, 10);




so i changed the program as following: i defined A, and declared get value! i have still troubles in this code!
#include <math.h>
#include <stdio.h>


#define PI  3.1415926535897932384626433832795
#define N   20

#define A ( 	int	n, double	x,double	y,int	degree	 )

int main()
{
    double x[N], y[N], getValue(float);
    int i;

    double xx = PI/2;
    double step = 2 * PI / (N - 1);

  for ( i = 0; i < N; ++i, xx += step)
  {
    double x2=xx+sin(xx);
    x[i] = x2;
    y[i] = sin(x2)/x2;
  }

    A ( N, x, y, 3);

    int N_out =50;
    xx = PI/2 ;
    step = 2 * PI / (N_out - 1);

  printf("\n x, exact, discrete_3");

  for ( i = 0; i < N_out; ++i, xx += step)
  {
    double x2=xx+sin(xx);
    printf("\n%.4lf, %.6lf, %.6lf", x2, sin(x2)/x2,getValue(x2));
  }
  return 0;
}


This post has been edited by Skydiver: 08 October 2013 - 07:55 PM
Reason for edit:: Put code in code tags. Learn to follow instructions.

Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3163
  • View blog
  • Posts: 9,556
  • Joined: 05-May 12

Re: error in the line 25, A Statement!

Posted 08 October 2013 - 07:55 PM

Put your code in codetags:
:code:
Was This Post Helpful? 1
  • +
  • -

#8 siri86  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 07-October 13

Re: error in the line 25, A Statement!

Posted 08 October 2013 - 08:55 PM

View PostSkydiver, on 08 October 2013 - 07:55 PM, said:

Put your code in codetags:
:code:/>


what would this change in the code?
Was This Post Helpful? -1
  • +
  • -

#9 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,735
  • Joined: 25-December 09

Re: error in the line 25, A Statement!

Posted 08 October 2013 - 08:58 PM

Quote

what would this change in the code?

It'll make your code readable! And if you don't start using code tags, you'll find your topics closed!



Jim
Was This Post Helpful? 1
  • +
  • -

#10 siri86  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 07-October 13

Re: error in the line 25, A Statement!

Posted 08 October 2013 - 09:08 PM

View Postjimblumberg, on 08 October 2013 - 08:58 PM, said:

Quote

what would this change in the code?

It'll make your code readable! And if you don't start using code tags, you'll find your topics closed!



Jim


i did it! but dosn't work and appears the error expected identier or '(' befor'[' taken.


or whats the right way to do it?
Was This Post Helpful? 0
  • +
  • -

#11 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,735
  • Joined: 25-December 09

Re: error in the line 25, A Statement!

Posted 08 October 2013 - 09:12 PM

Quote

i did it!

You did what, exactly?

Quote

but dosn't work

Why doesn't it work? You need to ask specific questions and if you're getting error messages post the complete error messages exactly as they appear in your development environment.

Jim
Was This Post Helpful? 1
  • +
  • -

#12 siri86  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 07-October 13

Re: error in the line 25, A Statement!

Posted 08 October 2013 - 09:17 PM

View Postjimblumberg, on 08 October 2013 - 09:12 PM, said:

Quote

i did it!

You did what, exactly?

Quote

but dosn't work

Why doesn't it work? You need to ask specific questions and if you're getting error messages post the complete error messages exactly as they appear in your development environment.

Jim


jim i put my code in code tags! and the error what i postet was the only error that appears!
Was This Post Helpful? 0
  • +
  • -

#13 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,735
  • Joined: 25-December 09

Re: error in the line 25, A Statement!

Posted 08 October 2013 - 09:23 PM

Quote

and the error what i postet was the only error that appears!

That is not the complete error message. Error messages have much more information embedded within them, such as the line numbers where the problems were detected.

For example when I compile your code I get these messages:

Quote

||=== c_homework, Debug ===|
main.c||In function ‘main’:|
main.c|8|error: expected ‘)’ before ‘n’|
main.c|25|note: in expansion of macro ‘A’|
main.c|25|warning: left-hand operand of comma expression has no effect [-Wunused-value]|
main.c|25|warning: left-hand operand of comma expression has no effect [-Wunused-value]|
main.c|25|warning: left-hand operand of comma expression has no effect [-Wunused-value]|
main.c|8|warning: statement with no effect [-Wunused-value]|
main.c|25|note: in expansion of macro ‘A’|
main.c|12|warning: variable ‘y’ set but not used [-Wunused-but-set-variable]|
main.c|12|warning: variable ‘x’ set but not used [-Wunused-but-set-variable]|
||=== Build finished: 1 errors, 6 warnings (0 minutes, 1 seconds) ===|


And with these messages, please explain what your trying to accomplish on line 8.


Jim

This post has been edited by jimblumberg: 08 October 2013 - 09:26 PM

Was This Post Helpful? 2
  • +
  • -

#14 siri86  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 07-October 13

Re: error in the line 25, A Statement!

Posted 08 October 2013 - 09:28 PM

View Postjimblumberg, on 08 October 2013 - 09:23 PM, said:

Quote

and the error what i postet was the only error that appears!

That is not the complete error message. Error messages have much more information embedded within them, such as the line numbers where the problems were detected.

Jim


yes, your'e right. the line number where the problem is detectet ist 8. to be honest i don't know how to use code tags! so my code it jet not readable!
Was This Post Helpful? 0
  • +
  • -

#15 siri86  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 12
  • Joined: 07-October 13

Re: error in the line 25, A Statement!

Posted 08 October 2013 - 09:36 PM

View Postjimblumberg, on 08 October 2013 - 09:23 PM, said:

Quote

and the error what i postet was the only error that appears!

That is not the complete error message. Error messages have much more information embedded within them, such as the line numbers where the problems were detected.

For example when I compile your code I get these messages:

Quote

||=== c_homework, Debug ===|
main.c||In function ‘main’:|
main.c|8|error: expected ‘)’ before ‘n’|
main.c|25|note: in expansion of macro ‘A’|
main.c|25|warning: left-hand operand of comma expression has no effect [-Wunused-value]|
main.c|25|warning: left-hand operand of comma expression has no effect [-Wunused-value]|
main.c|25|warning: left-hand operand of comma expression has no effect [-Wunused-value]|
main.c|8|warning: statement with no effect [-Wunused-value]|
main.c|25|note: in expansion of macro ‘A’|
main.c|12|warning: variable ‘y’ set but not used [-Wunused-but-set-variable]|
main.c|12|warning: variable ‘x’ set but not used [-Wunused-but-set-variable]|
||=== Build finished: 1 errors, 6 warnings (0 minutes, 1 seconds) ===|


And with these messages, please explain what your trying to accomplish on line 8.


Jim


i try to define the function A in the line 8. this function Initializes the regression approximation routine with known data points
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2