none
Error C2447

    Question

  • Hi, I'm new to C++ and I'm trying to create a basic program that will calculate the volume of a sphere based on a user's value for the radius.  I keep getting the following error when I try to build the solution:

    1>------ Build started: Project: volumeSphere, Configuration: Debug Win32 ------

    1>Compiling...

    1>sphereVolume.cpp

    1>c:\users\lis\documents\visual studio 2008\projects\volumesphere\volumesphere\spherevolume.cpp(14) : error C2447: '{' : missing function header (old-style formal list?)

    1>Build log was saved at "file://c:\Users\Lis\Documents\Visual Studio 2008\Projects\volumeSphere\volumeSphere\Debug\BuildLog.htm"

    1>volumeSphere - 1 error(s), 0 warning(s)

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

     

    Please could someone help - I'm utterly stumped as to where I've gone wrong?  My code is below:



    #include

    Please could someone help - I'm utterly stumped as to where I've gone wrong?  My code is below:



    #include

     

    <iostream>

    #include

     

    <cmath>

    using

     

    std::cout;

    using

     

    std::cin;

    using

     

    std::endl;

    const

     

    float PI (const float PI = 3.14159);

    double

     

    sphereVolume (double radius, const float PI)

    {

     

    return (4/3 * PI * pow(radius, 3));

    }

    double

     

    main();

    {

    cout <<

    "Enter a value for radius:" << endl;

    cin >> radius;

    double

     

    sphereVolume (double radius, const float PI)

    cout <<

    "sphereVolume is " << sphereVolume << endl;

    return

     

    0;

    }


    Thank you.  xx

    Sunday, November 01, 2009 11:52 AM

Answers

  • double radius;
    std::cout
    double sphereVolume (double radius, const double PI);

    • Marked as answer by sapphyr Sunday, November 01, 2009 12:14 PM
    Sunday, November 01, 2009 12:10 PM
  • sphereVolume in your code is the address of the function sphereVolune (0x001B1069)

    To correct do this

    cout << sphereVolume(radius, PI) << endl;

    and erase the statement

    double sphereVolume (double radius, const double PI);

    since your function is now being called in the cout statement

    • Marked as answer by sapphyr Sunday, November 01, 2009 12:27 PM
    Sunday, November 01, 2009 12:24 PM

All replies

  • No idea why it posted it like that should be: 

    #include <iostream>

    #include <cmath>

    using std::cout;

    using std::cin;

    using std::endl;

     

    const float PI (const float PI = 3.14159);

     

    double sphereVolume (double radius, const float PI)

    {

    return (4/3 * PI * pow(radius, 3));

    }

    double main();

    {

    cout << "Enter a value for radius:" << endl;

    cin >> radius;

    double sphereVolume (double radius, const float PI)

    cout << "sphereVolume is " << sphereVolume << endl;

    return 0;

    }

    Sunday, November 01, 2009 11:53 AM
  • use int main() instead of double main();

    don't use ; after main()
    Sunday, November 01, 2009 11:57 AM
  • Hi Belloc, 
    Thanks for replying so quickly.  I changed the code so it says:
     

    #include <iostream>

    #include <cmath>

    using std::cout;

    using std::cin;

    using std::endl;

     

    const float PI (const float PI = 3.14159);

     

    double sphereVolume (double radius, const float PI)

    {

    return (4/3 * PI * pow(radius, 3));

    }

    int main();

    {

    cout << "Enter a value for radius:" << endl;

    cin >> radius;

    double sphereVolume (double radius, const float PI)

    cout << "sphereVolume is " << sphereVolume << endl;

    return 0;

    }
    But it still returns the same error...  Any other ideas?

    Thanks.  xx

    Sunday, November 01, 2009 11:59 AM
  • Instead of

    const float PI (const float PI = 3.14159);

    use

    const float PI = 3.14159; 
    Sunday, November 01, 2009 12:00 PM
  • Replace int main();

    by

    int main()
    Sunday, November 01, 2009 12:02 PM
  • Changed it so now it is:

     

    #include <iostream>

    #include <cmath>

    using std::cout;

    using std::cin;

    using std::endl;

     

    const float PI = 3.14159;

     

    double sphereVolume (double radius, const float PI)

    {

    return (4/3 * PI * pow(radius, 3));

    }

    int main();

    {

    cout << "Enter a value for radius:" << endl;

    cin >> radius;

    double sphereVolume (double radius, const float PI)

    cout << "sphereVolume is " << sphereVolume << endl;

    return 0;

    }


    Now it is returning:

    1>------ Build started: Project: volumeSphere, Configuration: Debug Win32 ------

    1>Compiling...

    1>sphereVolume.cpp

    1>c:\users\lis\documents\visual studio 2008\projects\volumesphere\volumesphere\spherevolume.cpp(7) : warning C4305: 'initializing' : truncation from 'double' to 'const float'

    1>c:\users\lis\documents\visual studio 2008\projects\volumesphere\volumesphere\spherevolume.cpp(14) : error C2447: '{' : missing function header (old-style formal list?)

    1>Build log was saved at "file://c:\Users\Lis\Documents\Visual Studio 2008\Projects\volumeSphere\volumeSphere\Debug\BuildLog.htm"

    1>volumeSphere - 1 error(s), 1 warning(s)

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    :S

    Sunday, November 01, 2009 12:02 PM
  • Change int main();

    by

    int main()
    Sunday, November 01, 2009 12:04 PM
  • Changed int main(); to int main() and now I have:

    1>------ Build started: Project: volumeSphere, Configuration: Debug Win32 ------

    1>Compiling...

    1>sphereVolume.cpp

    1>c:\users\lis\documents\visual studio 2008\projects\volumesphere\volumesphere\spherevolume.cpp(7) : warning C4305: 'initializing' : truncation from 'double' to 'const float'

    1>c:\users\lis\documents\visual studio 2008\projects\volumesphere\volumesphere\spherevolume.cpp(16) : error C2065: 'radius' : undeclared identifier

    1>c:\users\lis\documents\visual studio 2008\projects\volumesphere\volumesphere\spherevolume.cpp(18) : error C3646: 'cout' : unknown override specifier

    1>c:\users\lis\documents\visual studio 2008\projects\volumesphere\volumesphere\spherevolume.cpp(18) : error C2143: syntax error : missing ';' before '<<'

    1>Build log was saved at "file://c:\Users\Lis\Documents\Visual Studio 2008\Projects\volumeSphere\volumeSphere\Debug\BuildLog.htm"

    1>volumeSphere - 3 error(s), 1 warning(s)

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Sunday, November 01, 2009 12:04 PM
  • To avoid the warning replace

    const float PI = ...;

    by

    const double PI = ...;

    Sunday, November 01, 2009 12:06 PM
  •  

    #include <iostream>

    #include <cmath>

    using std::cout;

    using std::cin;

    using std::endl;

     

    const double PI = 3.14159;

     

    double sphereVolume (double radius, const double PI)

    {

    return (4/3 * PI * pow(radius, 3));

    }

    int main()

    {

    cout << "Enter a value for radius:" << endl;

    cin >> radius;

    double sphereVolume (double radius, const double PI)

    cout << "sphereVolume is " << sphereVolume << endl;

    return 0;

    }

    Returns:

    1>------ Build started: Project: volumeSphere, Configuration: Debug Win32 ------

    1>Compiling...

    1>sphereVolume.cpp

    1>c:\users\lis\documents\visual studio 2008\projects\volumesphere\volumesphere\spherevolume.cpp(16) : error C2065: 'radius' : undeclared identifier

    1>c:\users\lis\documents\visual studio 2008\projects\volumesphere\volumesphere\spherevolume.cpp(18) : error C3646: 'cout' : unknown override specifier

    1>c:\users\lis\documents\visual studio 2008\projects\volumesphere\volumesphere\spherevolume.cpp(18) : error C2143: syntax error : missing ';' before '<<'

    1>Build log was saved at "file://c:\Users\Lis\Documents\Visual Studio 2008\Projects\volumeSphere\volumeSphere\Debug\BuildLog.htm"

    1>volumeSphere - 3 error(s), 0 warning(s)

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Sunday, November 01, 2009 12:08 PM
  • double radius;
    std::cout
    double sphereVolume (double radius, const double PI);

    • Marked as answer by sapphyr Sunday, November 01, 2009 12:14 PM
    Sunday, November 01, 2009 12:10 PM
  •  

    #include <iostream>

    #include <cmath>

    using std::cout;

    using std::cin;

    using std::endl;

     

    const double PI = 3.14159;

     

    double sphereVolume (double radius, const double PI)

    {

    return (4/3 * PI * pow(radius, 3));

    }

    int main()

    {

    double radius;

    cout << "Enter a value for radius:" << endl;

    cin >> radius;

    double sphereVolume (double radius, const double PI);

    cout << "sphereVolume is " << sphereVolume << endl;

    return 0;

    }

    Works! 

    Thank you so much for your help!  :)  xx

    Sunday, November 01, 2009 12:14 PM
  • you're welcome
    Sunday, November 01, 2009 12:16 PM
  • Although when I run the program it's giving the sphereVolume as 001B1069.... ??
    Sunday, November 01, 2009 12:19 PM
  • sphereVolume in your code is the address of the function sphereVolune (0x001B1069)

    To correct do this

    cout << sphereVolume(radius, PI) << endl;

    and erase the statement

    double sphereVolume (double radius, const double PI);

    since your function is now being called in the cout statement

    • Marked as answer by sapphyr Sunday, November 01, 2009 12:27 PM
    Sunday, November 01, 2009 12:24 PM
  • Thank you so much for all your help.  All works.  :)

    xx
    Sunday, November 01, 2009 12:27 PM