Thread: Need help finding error

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    7

    Need help finding error

    I am new to C++ and am working on an assignment for my class...

    The error i am getting is the following:
    Code:
    c:\documents and settings\matt\my documents\visual studio 2005\projects\assignment 1a\assignment 1a\assignment 1b.cpp(8) : error C2668: 'atan' : ambiguous call to overloaded function
    1>        c:\program files\microsoft visual studio 8\vc\include\math.h(545): could be 'long double atan(long double)'
    1>        c:\program files\microsoft visual studio 8\vc\include\math.h(497): or 'float atan(float)'
    1>        c:\program files\microsoft visual studio 8\vc\include\math.h(109): or 'double atan(double)'
    1>        while trying to match the argument list '(int)'
    The program:
    Code:
    #include <iostream>
    #include <string>
    #include <cmath>
    using namespace std;
    
    int main (void)
    {
    	const double PI = 4*atan(1); //the constant Pi
    	double d; //diameter
    	double r; //radius
    	double area; //area
    	string name;  //your name
    	
    	cout << "What is your name?" << endl;
    	cin >> name;
    
    	cout << "Enter the diameter of a circle:" << endl;
    	cin >> d;
    
    	r = 1/2 *d;
    	area = PI * r * r;
    
    	cout << "Hi " << name << ", the area of a circle with a diameter of " 
    		<< d << "is" << area << endl;
    
    	return 0;
    }
    its probably something very intuitive for someone who has some experience but please help me out

    thanks in advance!

  2. #2
    Registered User
    Join Date
    Jan 2007
    Posts
    31
    hi i think u might need to put this
    Code:
    const double PI = 4*atan(1.0);
    also if u put this u can see what happens
    Code:
    cout << "Hi " << name << ", the area of a circle with a diameter of " 
    		<< d << "is" << area << endl;
                    system("pause");
    	return 0;
    }

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    7
    Code:
    const double PI = 4*atan(1.0);
    Just tried it...

    I get this

    fatal error LNK1169: one or more multiply defined symbols found

    Code:
    cout << "Hi " << name << ", the area of a circle with a diameter of " 
    		<< d << "is" << area << endl;
                    system("pause");
    	return 0;
    Doesnt help either

  4. #4
    Registered User
    Join Date
    Jan 2007
    Posts
    31
    im running devcpp
    and as the code is written it worked fine with me so i guess its time
    for someone who knows what they doing to look at it sorry i cant be more help

    when u wrote the code in did u add a new line or did u change what u had already?

  5. #5
    Registered User
    Join Date
    Jan 2007
    Posts
    7
    what is devcpp? Is that the compiler u are using?

  6. #6
    Registered User
    Join Date
    Jan 2007
    Posts
    31
    yep

  7. #7
    Registered User
    Join Date
    Jan 2007
    Posts
    7
    I am using Visual C++ from microsoft if that has anything to do with it.

  8. #8
    Registered User
    Join Date
    Jan 2007
    Posts
    31
    ok im not very good at this myself but it sounds like u defined something twice?
    check your code to make sure any functions i.e main or variables are only defined once

  9. #9
    Registered User
    Join Date
    Jan 2007
    Posts
    7
    would it make a difference if i have another source file in the same program with that also has a variable named "name:?

  10. #10
    Registered User
    Join Date
    Jan 2007
    Posts
    31
    if u post all the source code ill see if i can fix it i do think that another name: in a source file will make an error if they are both in scope of each other

  11. #11
    Registered User
    Join Date
    Jan 2007
    Posts
    7
    ok. here is the other source File
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main(void)
    
    {
    	string name;
    	int age;
    
    	cout << "What's your name? " << endl;
    	cin >> name;
    
    	cout << "How old are you?" << endl;
    	cin >> age;
    
    	cout << "Hello "<< name
    		<< ", you will be " << age+1
    		<< " years old on your next birthday." << endl;
    
    	return (0);
    }
    and here is the second source file
    Code:
    #include <iostream>
    #include <string>
    #include <cmath>
    
    using namespace std;
    
    int main (void)
    {
    	const double PI = 4*atan(1.0);  //the constant Pi
    	double d; //diameter
    	double r; //radius
    	double area; //area
    	string n;  //your name
    	
    	cout << "What is your name?" << endl;
    	cin >> n;
    
    	cout << "Enter the diameter of a circle:" << endl;
    	cin >> d;
    
    	r = 1/2 *d;
    	area = PI * r * r;
    
    	cout << "Hi " << n << ", the area of a circle with a diameter of " 
    		<< d << "is" << area << endl;
           
    	return 0;
    }
    I am not sure what you mean by " in scope of each other".

  12. #12
    Registered User
    Join Date
    Jan 2007
    Posts
    7
    Oh i figured it out!!

    It didnt like that i had
    Code:
    int main (void);
    in the two source files!

    Thanks for your help anyways!

  13. #13
    Registered User
    Join Date
    Jan 2007
    Posts
    31
    ok i think the problem is u have 2
    Code:
    int main ()
    have u got these in a project file?

    i mean if a variable is global then u can only have that name once
    but if it is local to a function then u can have 2

    {

  14. #14
    Registered User
    Join Date
    Jan 2007
    Posts
    31
    lol well done an experienced c++ user would of spotted that straight away lol
    sorry to of hinderd ya

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM