Thread: Whats wrong with my find Circle Area program?[compiles fine]

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    156

    Whats wrong with my find Circle Area program?[compiles fine]

    I know there are some easier ways to perform this but I'm trying to get used to pointers and arrays[samething]. When the user types in the radius it doesn't return the current area.(pie * r2)

    Code:
    #include <iostream>
    
    inline float GetArea(float *buffer, float radius)
    {
     buffer= new float[5];
     buffer[2]= radius * radius;
     buffer[1]= 3.14;
     buffer[0]= buffer[2]*buffer[1];
     return buffer[0];
    }
    
    int main(int argc, char **argv)
    {
     float mybuffer, radius;
     cout << "Input the radius: ";
      cin >> radius;
     GetArea(&mybuffer, radius);
     cout << "The Area is: " << &mybuffer;
    
     cin.get();
     return 0;
    }
    Compiler: MingW(IDE: Bloodshed Dev-C++ 4.01)
    Web Site: Zoo Crew
    Forums: Zoo Boards
    E-mail: [email protected]

    "Do you wanna go to jail or do you wanna go home?!?!" - Alonzo(Training Day)

  2. #2
    Unregistered
    Guest
    what do you want the program to do becuz if u just want it to find the area than i think it can be done much more easily

  3. #3
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    GB knows this but GB is tryin to use pointers...

    and arrays..
    What is C++?

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    156
    Looks like someone didn't really read my post
    Compiler: MingW(IDE: Bloodshed Dev-C++ 4.01)
    Web Site: Zoo Crew
    Forums: Zoo Boards
    E-mail: [email protected]

    "Do you wanna go to jail or do you wanna go home?!?!" - Alonzo(Training Day)

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    ok. then i dont see the problem with his code maybe you can help.

    ( i was the unregistered person)

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    156
    ok
    Compiler: MingW(IDE: Bloodshed Dev-C++ 4.01)
    Web Site: Zoo Crew
    Forums: Zoo Boards
    E-mail: [email protected]

    "Do you wanna go to jail or do you wanna go home?!?!" - Alonzo(Training Day)

  7. #7
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    if you can get the code post it i want to know whats wrong with it
    let me know it that help plz



    #include <iostream.h>
    #include <conio.h>
    double mult(double x, double y);

    int main()
    {
    double x, y = 3.14;
    cout<<"Please input your radius: ";
    cin>>x;
    cout<<"The area is "<<mult(x, y);
    getch();
    return 0;
    }
    double mult(double x, double y)
    {
    return x*y*x;
    }


    this is a way of doing it w/ a function it works. i used getch() for my stupid compiler closing when i launch the program
    Last edited by gamer4life687; 06-15-2002 at 09:09 PM.

  8. #8
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    uh dude... use code tags... or youll be hated here....

    put [ code ] and [ / code ] around your code.

    without spaces of course..
    What is C++?

  9. #9
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    i dont quite catch what your saying im kind of new here hehehe do you mean


    code:


    #include <iostream.h>
    #include <conio.h>
    double mult(double x, double y);

    int main()
    {
    double x, y = 3.14;
    cout<<"Please input your radius: ";
    cin>>x;
    cout<<"The area is "<<mult(x, y);
    getch();
    return 0;
    }
    double mult(double x, double y)
    {
    return x*y*x;
    }





    like that
    Last edited by gamer4life687; 06-15-2002 at 09:29 PM.

  10. #10
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    no like
    this

    Code:
    Code:
     < put that above your code
    <<that below your code...
    What is C++?

  11. #11
    Registered User
    Join Date
    Apr 2002
    Posts
    156
    Ok, over here we use a web development language known as PHP. Very similiar to HTML. If you want your source code to be readible you must go like this [ code ] before your code, and to end it you go like this [ /code ]. I know how to do this the simple way.

    Code:
    #include <iostream>
    #define done 0
    
    inline float Area(float pie, float radius)
    {
     return pie*(radius*radius);
    }  
    
    int main()
    {
     float x;
     cout << "Input the radius: ";
     cin >> x;
     cout << "The Area is: " << Area(3.14, x);
    
     cin.get();
     return done;
    }
    But I won't to do it the pointer/array way.
    Compiler: MingW(IDE: Bloodshed Dev-C++ 4.01)
    Web Site: Zoo Crew
    Forums: Zoo Boards
    E-mail: [email protected]

    "Do you wanna go to jail or do you wanna go home?!?!" - Alonzo(Training Day)

  12. #12
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    thanks and did you figure out you code problems yet i really want to know whats wrong cuz i cant figure it out

  13. #13
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    that code does work so i guess its figured out the easy way then

  14. #14
    Registered User
    Join Date
    Apr 2002
    Posts
    156
    After the user types in the radius, it doesn't return the proper area.
    Compiler: MingW(IDE: Bloodshed Dev-C++ 4.01)
    Web Site: Zoo Crew
    Forums: Zoo Boards
    E-mail: [email protected]

    "Do you wanna go to jail or do you wanna go home?!?!" - Alonzo(Training Day)

  15. #15
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    maybe you have the wrong formula or maybe you checkec it wrong cuz it workes for me, both of the codes mine and the other one. area = pie * radius^2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someone find out what i'm doing wrong?
    By QuincyEQ in forum C Programming
    Replies: 2
    Last Post: 08-15-2002, 11:22 AM
  2. Whats wrong with my file streaming[it compiles fine]
    By Golden Bunny in forum C++ Programming
    Replies: 3
    Last Post: 06-14-2002, 08:43 PM
  3. Help i cant find whats wrong with my code
    By 0927 in forum C++ Programming
    Replies: 1
    Last Post: 12-21-2001, 09:14 PM
  4. point lies in circle?
    By cozman in forum Game Programming
    Replies: 3
    Last Post: 12-20-2001, 04:39 PM
  5. Help me find out what's wrong
    By biosx in forum C Programming
    Replies: 4
    Last Post: 08-15-2001, 12:37 PM