1 Replies - 667 Views - Last Post: 20 April 2012 - 12:58 AM Rate Topic: -----

#1 bennigan88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 07-April 12

double is not class/struct/union error in Length of Curve program

Posted 20 April 2012 - 12:23 AM

When I run this, I get an error that I don't understand, and it references what I'm assuming to be a library. The error reads "'double' is not class, struct, or union type". I am not familiar with class or structures yet, so I obviously have not incorrectly attempted to use one, but I can't see the syntax error.

This program is supposed to divide up a domain into n parts, each part having two points whose x values are (b-a)/n apart from each other. It then is supposed to add up the lines into a total sum.

#include <iostream>
#include <cmath>

using namespace std;

double f(double x);
double distance(double x1, double x2);

int main()
{

    int n=0, a=0, b=0;
    cout << "Enter number of segments to divide curve into: ";
    cin >> n;
    cout << "Enter the domain in the format (a B)/>: ";
    cin >> a >> b;
    double dx=0;
    dx=(b-a)/n;

    double d=0;
    double sum=0;
    
    for (int i=0; i<=n; i++)
    {

        
        cout << "Distance between f(" << (a+dx*i) << ") and f(" << (a+dx*(i+1)) << ") = ";
        d=distance((a+(dx*i)),(a+(dx*(i+1))));
        cout << d;
        sum=+d;
        
    }
    cout << endl << "Total length is " << sum;


    return 0;
}

double f(double x)
{
    return cos(x);
}
double distance(double x1, double x2)
{
    double d=sqrt(pow(x2-x1,2)+pow(f(x2)-f(x1),2));
    return d;
}




Is This A Good Question/Topic? 0
  • +

Replies To: double is not class/struct/union error in Length of Curve program

#2 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: double is not class/struct/union error in Length of Curve program

Posted 20 April 2012 - 12:58 AM

double distance(double x1, double x2);
Function name conflict with std::distance().
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1