Thread: Beginners ERROR!!!

  1. #1

    Question Beginners ERROR!!!

    OK the prob is my book is tellin me to make a program that calculates the area of a circle with radius 4 and pie being 3.14159. Now I know how to to the calculation but I keep getin these errors sayin that I'm assigning values I never use but I do. Here see what I mean. I'll put the error messages after the code.
    Code:
    //Review Quesitons Pg 136 # 2
    #include <iostream.h>
    int main()
    {
      int radius = 4;
      float pie = 3.14159;
      float C_Area;
    
      cout << "The area of a circle with radius of 4 is: " << endl;
      cout << C_Area = pie * (radius * radius) << endl;
    
      system ("Pause");
      return 0;
    }
    ...and the error messages are:
    1. Overloaded 'endl' ambiguous in the context in function main()
    2. 'pie' is assigned a value that is never used in function main()
    3. 'radius' is assigned a value that is never used in function main()

    So if anyone can first explain exactly what the errors mean and then tell me what my solution should be I would be greatful. I just don't understand why it's sayin i'm assigning values that are never used when I'm makin the variables and initializing them and then using them in my equation. Anyway thanks for any help I get.
    -T

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Code:
    //Review Quesitons Pg 136 # 2
    #include <iostream.h>
    #include <stdlib.h>
    int main()
    {
      int radius = 4;
      float pie = 3.14159;
      float C_Area;
    
      cout << "The area of a circle with radius of 4 is: " << endl;
      C_Area = pie * (radius * radius);
      cout << C_Area << endl;
    
      system ("Pause");
      return 0;
    }
    Notice that the equation was moved out of the cout statement. system() is in stdlib.h.

  3. #3
    Thanks. I'm really dumb for not seein that. Oh and by the way you don't have to use stdlib.h to use system ("Pause");
    It's just used to pause the program until the user hits enter, but you probly already knew that.
    -T

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    53
    What hits me straight in the face is that you both use iostream.h in a C++ forum lol
    By the way, system( "pause" ) is evil

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    53
    Corrected version:
    Code:
    //Review Quesitons Pg 136 # 2
    #include <iostream>
    
    using std::cout ;
    using std::endl ;
    using std::cin ;
    
    int main()
    {
      int radius = 4;
      float pie = 3.14159;
      float C_Area;
    
      cout << "The area of a circle with radius of 4 is: " << endl;
      C_Area = pie * (radius * radius);
      cout << C_Area << endl;
    
      cin.get( ) ;
      return 0;
    }

  6. #6
    "What hits me straight in the face" (whatever that means) is when people fail to read thread titles like the one here that says "Beginner" and think maybe thats the way they are learning. I know I'm using the old methods. This has been brought to my attention before but the book I'm using (which was published in '92 by the way) is showing me this way and so thats the way I'm learning it now. But thanks for your 'constructive' criticisim and your willingness to take time out to reply to my thread.
    -T

  7. #7
    Registered User
    Join Date
    Jul 2004
    Posts
    53
    I didn't want to be mean, it's only that I wanted to point you out that thing that was really easy to see that's why I said it hit me straight in the face... if you don't want to have it complicated, only change to iostream and put the line "using namespace std ;" under your includes, it's not really ok to do this since it makes the use of the STD library useless but that's a start... I hope you understand I only really want to help you

  8. #8
    Thanks man. You know it just gets a little stressful when ever your tryin to learn somethin new and all the so called 'pro' (more like wanna be's) keep tryin to make ya feel stupid. But really thanks for you help and my bad. I'll start tryin to learn the new methods when I start getin a better handle on things. Thanks.
    -T

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM