-
October 31st, 2009, 11:02 AM
#1
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 !
-
October 31st, 2009, 11:24 AM
#2
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
-
October 31st, 2009, 01:28 PM
#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.
-
October 31st, 2009, 01:42 PM
#4
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.
-
October 31st, 2009, 01:54 PM
#5
Re: URGENT!!! I NEED your HELP!!
Originally Posted by GCDEF
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?
-
October 31st, 2009, 04:15 PM
#6
Re: URGENT!!! I NEED your HELP!!
Originally Posted by alizee67
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|