Not sure how to start Circles assignment

Write a C++ program that defines a global constant named PI with a value of 3.14159 and local variables for radius, with a value of 6, and diameter, with a value of 12. Then, calculate the area and circumference of a circle, using each of the equations found in the attached document, and store the results in variables named areaR, circumferenceR, areaD, and circumferenceD. You will need to include math.h and pow() to compute the square of a value. Make sure that you display all results to the screen.

Any help would be appreciated.
What have you done so far?
#include <iostream>
#include <cmath>
#define PI 3.14159
using namespace std;

int main()
float areaR, circumferenceR, areaD, circumferenceD;
float radius, diameter;

radius = 6; diameter = 12;
areaR = pow((PI * radius), 2);
circumferenceR = (PI * diameter);

// This assignment confuses me.. why would there be two different values for
// each area and circumference when radius and diameter are describing just
// one circle? so you can figure out what to do with those other two variables.

cout << "Area of circle: " << areaR << "\n";
cout << "Circumference: " << circumferenceR << "\n";
return 0;
The other variables I was given from my teacher were:

The circumference D = PI * diameter


The Area D = ((PI * diameter), 2)/ 4
This is considered a char: \n. You'll want to put these into single parenthesis:


You'll also want to use math.h and not cmath.

notice what you are doing here:
areaR = pow((PI * radius), 2);
circumferenceR = (PI * diameter);

The instructions call for the use of 4 variables, areaR and circumfrenceR, and areaD and circumfrenceD. This means that you need to use both radius and diameter when calculating your variables.
oh, I see, you are supposed to get the area and circumference using both..
kinda redundant but ok

areaR = pow((PI * radius), 2);
areaD = pow((PI * diameter / 2), 2);
// OR areaD = (pow((PI * diameter), 2) / 4);
circumferenceR = (PI * radius * 2);
circumferenceD = (PI * diameter);

so that should give you the same value for areaR and areaD, and the same for circumferenceR and circumferenceD.. seems to me it'd be best to pick one and stick with it lol but if that's what ya gotta do..
"\n" never killed anyone and neither has cmath to my knowledge, limited as it is
Last edited on
Thats your professor. Its probably just for practice.
Thanks for the help.
Last edited on
oh werd my baD
Last edited on
.h files are written in c, where as the include files that have no extension are written in c++.

you should use cmath usually, but the instructions call for math.h.
Last edited on
My professor gave us a note that he wanted us to use cmath, he made an error.
Last edited on
Does anyone notice that the area of circle is pi * r^2 or PI * pow(radius, 2);, not (pi * r)^2 pow((PI * radius), 2); ? O.o
whoa good catch lol whoops
Topic archived. No new replies allowed.