CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    May 2015
    Posts
    21

    #define not working with my input

    Code isn't fully complete but I don't want to continue when my #define isn't even working, what am I doing wrong here? Please help, and go easy on me, this is my first code ever. Thanks!

    #define PI 3.14159
    #include <iostream>
    using namespace std;

    int main()

    {

    int answer;
    cout << "The area of a circle is" <<PI>> "* radius * radius"<<endl; //This line is a calculation and cannot be done until you read in the radius from the user, i.e. you cannot do a calculation until

    //Ask the user for the radius of the pie in inches.
    cout << "What is the radius of the pie in inches?" << endl;
    //read in the radius

    //Ask the user for the length of the shelf.
    cout << "What is the length of the shelf?" <<endl;
    //readin the length

    //Ask the user for the width of the shelf.
    cout << "What is the width of the shelf?" <<endl;
    //read in the width

    //Calculate the area of the pie.

    //Calculate the area of the shelf.
    //ex: sum = num1 + num2; example of a sum calculation

    //Calculate the total number of pies that can fit on the shelf.
    cout << "What is the total number of pies that can fit on the shelf?" <<endl; //This is not an output statement this is also a calculation, your answer which should be the area of your shelves
    //divided by the area of your pies
    system("pause");
    //Display a message telling the user how many pies can fit on the shelf
    cout << "The number of pies that can fit on the shelf is" << answer << endl;
    return 0;
    }

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: #define not working with my input

    Your #define is working fine. You have a little issue here though

    cout << "The area of a circle is" <<PI>> "* radius * radius"<<endl;

  3. #3
    Join Date
    May 2015
    Posts
    21

    Re: #define not working with my input

    Thanks for the reponse. Maybe it's my compiler, I'm using DevC++ 5.11. When I type in #define PI 3.14159 it all stays once color when I thought "PI" was suppose to be a different color, I don't know. Still says it's incorrect, like it's not acknowledging my #define.

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: #define not working with my input

    Once I changed the >> to << it compiled cleanly for me using VS 2012.

  5. #5
    Join Date
    May 2015
    Posts
    21

    Re: #define not working with my input

    Guess I'll be trying a new compiler, thanks a lot GCDEF

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: #define not working with my input

    When posting code, please use code tags. Go Advanced, select the formatted code and click '#'.

    Still says it's incorrect, like it's not acknowledging my #define.
    Have you changed your code as per GCDEF's post? What is incorrect? What error message is the compiler displaying?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: #define not working with my input

    Possibly that compiler has something else already defined as PI. Try calling it something else. The exact error message would help.

  8. #8
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: #define not working with my input

    Quote Originally Posted by deadfolx View Post
    Guess I'll be trying a new compiler, thanks a lot GCDEF
    If you are using Windows, have a look at MS VS 2013 community edition. This is free. See https://www.visualstudio.com/downloa...sual-studio-vs
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  9. #9
    Join Date
    May 2015
    Posts
    21

    Re: #define not working with my input

    Excellent thank you. My apologies for not using a tag, I'll do so in the future for sure. As far as the code is concerned, it was saying that there was no given value for "PI" and highlighted the entire line in red.

  10. #10
    Join Date
    May 2015
    Posts
    21

    Re: #define not working with my input

    Fixed it guys, thanks again
    Last edited by deadfolx; May 7th, 2015 at 03:56 PM.

  11. #11
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: #define not working with my input

    Quote Originally Posted by deadfolx View Post
    Fixed it guys, thanks again
    What was it?

  12. #12
    Join Date
    May 2015
    Posts
    21

    Re: #define not working with my input

    Quote Originally Posted by GCDEF View Post
    What was it?
    it was a stupid mistake...I put the #define in the wrong spot and some other careless mistakes that I looked over. And devc++ was a P.O.S compiler, VS is much better, thanks again GCDEF

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured