Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does the compiler say pow(n,k) ambiguous in this code?
    primarykey
    data
    text
    <p>When compiling the following code under Xcode 4.5 (Mac), compilation fails with the following error message:</p> <pre><code>call to 'pow' is ambiguous </code></pre> <p>Why? Thanks!</p> <pre><code>#include &lt;iostream&gt; #include &lt;cmath&gt; #include &lt;limits&gt; using namespace std; int main() { cout &lt;&lt; "\tSquare root calculator using an emulation the ENIAC's algorithm." &lt;&lt; endl &lt;&lt; endl; long long m; while ((cout &lt;&lt; "Enter a positive integer:" &lt;&lt; endl) &amp;&amp; (!(cin &gt;&gt; m) || m &lt; 0 || m &gt; 9999999999)) //10-digit maxium { cout &lt;&lt; "Out of range."; cin.clear(); cin.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n'); } again: long long l = m; //Find out how big the integer is and adjust k accordingly. int order = -1; long long temp = m; do { temp /= 10; order++; } while (temp/10); int k = order/2; //Step 1 long long a = -1; do { a+=2; m -= a*pow(100,k); } while (m &gt;= 0); while (k &gt; 0) { k--; //Step 2 if (m &lt; 0) { a = 10*a+9; for (;m &lt; 0;a -= 2) { m += a*pow(100,k); } a += 2; } //Step 3 else { a = 10*a-9; for(;m &gt;= 0;a += 2) { m -= a*pow(100,k); } a -= 2; } } //Step 4 cout &lt;&lt; endl &lt;&lt; "The square root of " &lt;&lt; l &lt;&lt; " is greater than or equal to " &lt;&lt; (a-1)/2 &lt;&lt; " and less than " &lt;&lt; (a+1)/2 &lt;&lt; "." &lt;&lt; endl &lt;&lt; endl; while ((cout &lt;&lt; "Enter a positive integer to calculate again, or zero to exit." &lt;&lt; endl) &amp;&amp; (!(cin &gt;&gt; m) || m &lt; 0 || m &gt; 9999999999)) { cout &lt;&lt; "Out of range."; cin.clear(); cin.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n'); } if (m &gt; 0) goto again; return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload