-
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!
-
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;
}
-
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
-
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?
-
what is devcpp? Is that the compiler u are using?
-
-
I am using Visual C++ from microsoft if that has anything to do with it.
-
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
-
would it make a difference if i have another source file in the same program with that also has a variable named "name:?
-
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
-
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".
-
Oh i figured it out!!
It didnt like that i had
in the two source files!
Thanks for your help anyways!
-
ok i think the problem is u have 2 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
{
-
lol well done an experienced c++ user would of spotted that straight away lol
sorry to of hinderd ya :( :)