CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2009
    Posts
    3

    URGENT!!! I NEED your HELP!!

    Hi guys!
    I have an assignment for my C++ programming course. The deadline is 2009/11/1 ! (I know it's too late, but plzzzz!!) I would really appreciate it if you could help me.
    The problem is:
    Write a program which calculates and prints the area and circumference of a circle with 2 functions.
    THANKS A LOT !

  2. #2
    Join Date
    Oct 2005
    Location
    England
    Posts
    803

    Re: URGENT!!! I NEED your HELP!!

    Post the code you have so far then indicate any specific issues you are having.
    Rich

    Visual Studio 2010 Professional | Windows 7 (x64)
    Ubuntu

  3. #3
    Join Date
    Oct 2009
    Posts
    3

    Re: URGENT!!! I NEED your HELP!!

    OK, Thanks !
    Here's the code I've written:

    #include <iostream>
    #include<iomanip>
    using namespace std;
    void circ(float circum);
    void are(float area2);
    float circum, circumference, radius, area2, area;
    int main()
    {
    cout << setiosflags(ios::fixed) << setprecision(2); //sets decimal places
    cout << "This program displays the area and circumfrence of a circle using two functions.\n\n";
    cout << "Please enter the radius of your circle: ";
    cin >> radius;
    circ(circumference);
    are(area2);
    cout << endl;
    cout << "The circumference of your circle is " << circumference << ".\nThe area of your circle is " << area << endl << endl;
    }
    void circ(float circum)
    {
    circumference = 3.14*(radius*2);
    }
    void are(float area2)
    {
    area = 3.14 * (radius*radius);
    }


    I appreciate any help.

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

    Re: URGENT!!! I NEED your HELP!!

    You need to pass the radius that you get in main as an argument to the functions, and rather than using global variables, your functions should return the calculated value. You're close.

  5. #5
    Join Date
    Oct 2009
    Posts
    3

    Re: URGENT!!! I NEED your HELP!!

    Quote Originally Posted by GCDEF View Post
    You need to pass the radius that you get in main as an argument to the functions, and rather than using global variables, your functions should return the calculated value. You're close.
    Could you please explain more?

  6. #6
    Join Date
    Oct 2005
    Location
    England
    Posts
    803

    Re: URGENT!!! I NEED your HELP!!

    Quote Originally Posted by alizee67 View Post
    Could you please explain more?
    Code:
    "What is the output type" circ ("What values do you need to calculate the circumference?")
    {
    
      return "The result of the calculation";
    
    }
    
    //Example:
    
    
    long square(int numberToSquare)
    {
       return numberToSquare * numberToSquare;
    }
    This removes the need for your global variables.
    Rich

    Visual Studio 2010 Professional | Windows 7 (x64)
    Ubuntu

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