Keep getting Errors!

Pages: 12
ok...the equation and everything works perfactly..but when I use my whole code together, it stats giving me Pow Ambiguous error..any idea for that?
Paste the code that uses the pow function. If you're using it in a function, paste the whole function. Also, copy/paste your error code. If the error has a line number, add a comment to point to the original line number.
ok...I did copy and past it. I think I made all changes..but here is the code and the error output.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<iostream>
#include<cmath>

using namespace std;

double PI = M_PI;
const double ZERO = 0.0001;
int a;
int b;

int main() {//Main method

bool quit = false;
string yn; //String for user input

while(not quit) {

//Enter and get the values for a and b.
cout << "Enter the Value for 'a' : " << endl;
cin >> a;//input the value of a
cout << "Enter the Value for 'b' : " << endl;
cin >> b;//input the value of b

//Method to draw an Ellipse
for (int row = 0; row < 24; row++) {
int y = 12-row;
for (int col = 0; col < 80; col++) {
double x = (40 - col)/2;
if (((pow(x,2) /pow(a,2)) + (pow(y,2) /pow(b,2)) - 1.0) < 0.0001)
cout << "@";
else
cout<< " ";
}//End of for
}//end of for

/** Method to check if it is a circle or an Ellipse. And print out the radius, area **/
//Method to test if it is a circle or and ellipse
if (a==b){
cout << "Circle :: " << " radius = " << a << " :: area = " << PI*a*a <<  endl;
} else {
cout << "Ellipse :: " << " a = " << a << " b = " << b << " :: area = " << PI*a*b <<endl;
 }
cout << "GO again? (Y/N) ";// asks user for repeating
cin >> yn; //taking user input
if(yn != "Y" && yn != "y")
quit = true;
}
}//End of main method



hw2.cpp: In function 'int main()':
hw2.cpp:30: error: call of overloaded 'pow(int&, int)' is ambiguous
/usr/include/bits/mathcalls.h:154: note: candidates are: double pow(double, double)
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/cmath:361: note:                 long double std::pow(long double, int)
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/cmath:357: note:                 float std::pow(float, int)
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/cmath:353: note:                 double std::pow(double, int)
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/cmath:349: note:                 long double std::pow(long double, long double)
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/cmath:345: note:                 float std::pow(float, float)
hw2.cpp:30: error: call of overloaded 'pow(int&, int)' is ambiguous
/usr/include/bits/mathcalls.h:154: note: candidates are: double pow(double, double)
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/cmath:361: note:                 long double std::pow(long double, int)
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/cmath:357: note:                 float std::pow(float, int)
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/cmath:353: note:                 double std::pow(double, int)
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/cmath:349: note:                 long double std::pow(long double, long double)
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/cmath:345: note:                 float std::pow(float, float)
hw2.cpp:30: error: call of overloaded 'pow(int&, int)' is ambiguous
/usr/include/bits/mathcalls.h:154: note: candidates are: double pow(double, double)
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/cmath:361: note:                 long double std::pow(long double, int)
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/cmath:357: note:                 float std::pow(float, int)
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/cmath:353: note:                 double std::pow(double, int)
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/cmath:349: note:                 long double std::pow(long double, long double)
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/cmath:345: note:                 float std::pow(float, float)



I have a feeling that it is a really silly mistake I am making but I will be honest I have no idea what to do about it.

@Volatile Pulse I really really appreciate all your help.
Well basically it says that you can't call pow with two ints (i.e. pow(1,2)) so the solution that should work (if you still want to keep your variables ints) is to change the second parameter (2) to a double (2.0). The other option is to change all of your variables to atleast a float or double.

I swore I was using pow with ints, but it might have been before I switched them back to ints and when they were still floats.
haha...i swear man..i am about to give up on this..now that the program compiles, the damn shapes went out of order..the @'s are all over the screen.
With out the pow function, the program runs great..but the shapes are not accurate..and with pow function, the output is all over the dang screen
This is what I just ran on my computer:
1
2
3
4
5
6
7
8
9
10
11
//Method to draw an Ellipse
      for (int row = 0; row < 24; row++) {
         int y = 12 - row;
         for (int col = 0; col < 80; col++) {
            double x = (40 - col) / 2.0;
            if (((pow(x, 2.0) / pow(a, 2.0)) + (pow(y, 2.0) / pow(b, 2.0)) - 1.0) < ZERO)
               cout << "@";
            else
               cout << " ";
         }//End of for
      }//end of for 


Notice the 2.0 in the assignment for x and the 2.0 to force the use of pow and changed .0001 to ZERO. Nothing else was changed and the shape is very crisp. I'm sure you know this, but make sure a isn't larger than 20, and b isn't larger than 12. Also, according to the design pattern, a must be larger than b.

I hope this solves your issues.
holy smokes it worked perfectly...
man..you are awsome..the program and the shapes are great
thank you so very much man.
thank you.
Topic archived. No new replies allowed.
Pages: 12