Thread: a prob?

  1. #1
    Registered User o0o's Avatar
    Join Date
    Dec 2003
    Posts
    37

    Unhappy a prob?

    Code:
    #include<iostream>
    #include<conio.h>
    using std::cout;
    using std::cin;
    using std::endl;
    // function prototype
    double small(double,double);  
    
    int main()
    {
        // declare varibales
        double num1,num2;   
        // read values
        cout<< "Enter two double values:\t";    
        cin>> num1 >> num2;
        // display result
        cout<< small(num1,num2);
    
    getch();
    }
    // define small()
    double small(double value1,double value2)
    {   
        // declare alias
        double minValue;
        // check smallest value
        double minValue=value1;
        if(value2<minValue)
        minValue=value2;
        return minValue;
    }
    It gives me parse errors before functions prototype.

    The same code when tries with an integer value gives correct output. What is wrong in this code?

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    You have a redefinition of minValue in your small function and your main doesn't return a value.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User o0o's Avatar
    Join Date
    Dec 2003
    Posts
    37
    didn't get that/

  4. #4
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146

    Re: a prob?

    Code:
    #include<iostream>
    #include<conio.h>
    using std::cout;
    using std::cin;
    using std::endl;
    // function prototype
    double small(double,double);  
    
    int main()
    {
        // declare varibales
        double num1,num2;   
        // read values
        cout<< "Enter two double values:\t";    
        cin>> num1 >> num2;
        // display result
        cout<< small(num1,num2);
    
    getch();
        return 0; // I think recent standards say this is implicit, but why leave it to chance?
    }
    // define small()
    double small(double value1,double value2)
    {   
        // declare alias
        double minValue;
        // check smallest value
        /*double*/ minValue=value1; // You can only define a variable once
        if(value2<minValue)
        minValue=value2;
        return minValue;
    }
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  5. #5
    Registered User o0o's Avatar
    Join Date
    Dec 2003
    Posts
    37
    got it now thanku/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Deal or No Deal listbox prob
    By kryptkat in forum Windows Programming
    Replies: 5
    Last Post: 03-30-2009, 06:53 PM
  2. wierd fopen prob
    By winterflood_j in forum C Programming
    Replies: 10
    Last Post: 02-24-2004, 06:31 AM
  3. prob function call
    By mouse163 in forum C++ Programming
    Replies: 4
    Last Post: 12-18-2002, 12:16 PM
  4. if-else prob..very basic so sorry to trouble u guys
    By bugeye in forum C Programming
    Replies: 2
    Last Post: 01-26-2002, 08:55 AM
  5. prob with fopen
    By ukcpaul in forum C Programming
    Replies: 2
    Last Post: 01-09-2002, 08:23 AM