Thread: error C2668: 'sqrt' : ambiguous call to overloaded function ???

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    54

    error C2668: 'sqrt' : ambiguous call to overloaded function ???

    I'm using Microsoft Visual C++ and have this lab due in a couple hours......

    However, everytime I try to run it I keep getting "error C2668: 'sqrt' : ambiguous call to overloaded function", and for the life of me I cannot understand why......

    Any help would be greatly appreciated! Thanks!

    Code:
    #include <stdio.h>
    #include <math.h>
    
    int main(void)
    {
      
        int i, n;
        float s;
        
    
        printf("Enter an Integer: ");
        scanf("%d", &n); /* obtain number */
        	
        if (n>0)
        {
            for(i=1;i<=n; i++) /* cycle through 1 to n */
            {
    	    s = sqrt(i); /* obtain the square root */	
    
                if (fmod(s,2) == 0) /* use floating point modular because sqrt returns a float */
    				/* if the remainder of a division by 2 is 0, then the number is even */
    
    		printf("%d\n", (int)i); /* print i value resulting in even square roots */
               
            }  
        } 
        else
        {
            printf("Sorry, try inputting a positive number next time.\n");
        }
    
    return 0;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Compile your code as C, not C++.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    54
    ....how would i do that in Microsoft Visual C++?

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    54
    figured it out. cheers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. how to get function call stack
    By George2 in forum C Programming
    Replies: 18
    Last Post: 11-11-2006, 07:51 AM
  4. C2668 - Ambiguous Call to Overloaded Function
    By Osiris990 in forum C++ Programming
    Replies: 6
    Last Post: 10-26-2005, 06:34 AM
  5. ambiguous call to overloaded function
    By LurPak in forum C++ Programming
    Replies: 2
    Last Post: 09-05-2003, 03:37 AM