C++ help i need help with a program im trying to get to work
Sep 24, 2014 at 7:31pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
const double PI = 3.1416;
// Student adds code for distance function prototype
double distance (char ch);
// Student adds code for radius function prototype
double radius (char ch);
// Student adds code for circumference function prototype
double circumference (char ch);
// Student adds code for area function prototype
bool area (char ch);
int main()
{
double x1, x2, y1, y2;
double circleRadius;
cout << fixed << showpoint << setprecision(2);
cout << "Enter the x and y coordinates of the center of the circle: " ;
cin >> x1 >> y1;
cout << endl << endl;
cout << "Enter the x and y coordinates of a point on the circle: " ;
cin >> x2 >> y2;
cout << endl << endl;
circleRadius = sqrt(x2 - x1)*2 + (y2-y1)*2; // Student adds code to use radius function.
cout << "Radius = " << circleRadius << endl;
cout << "Diameter = " << 2 * circleRadius << endl;
cout << "Circumference = " << 2 * PI * circleRadius << endl;/* Student adds code to use circumference function */
cout << "Area = " << PI * pow(circleRadius, 2) << endl;/* Student adds code to use area function */
return 0;
}
// Student adds code for distance function header and definition
double distanceFormula(sqrt(x2 - x1)*2 + (y2 - y1)*2)
{
double distance;
return distance;
}
// Student adds code for radius function header and definition
double radiusFormula(circumference / 2 * PI)
{
double radius;
return radius;
}
// Student adds code for circumference function header and definition
double circumferenceFormula(2 * PI * circleRadius * 2)
{
double circumference;
return circumference;
}
// Student adds code for area function header and definition
double areaFormula(PI * circleRadius * 2)
{
double area;
return area;
}
this is what i got so far but i need help with like the formula and what to put in it cause i dont think i
Sep 24, 2014 at 11:33pm UTC
It looks like you're trying to put the formula in the parameters? The code then just declares a variable area, doesn't give it a value, and returns whatever uninitialized value it has.
1 2 3 4 5
double areaFormula(PI * circleRadius * 2)
{
double area;
return area;
}
Here's just one example of a function that calculates the area of a circle given a radius, and how it could be called from the main function to print out the value it calculates.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
const double PI = 3.1416;
int main()
{
double radius = 10.5;
std::cout << "Area of circle with radius " << radius << " is " << calculateArea(radius) << std::endl;
return 0;
}
double calculateArea (double r)
{
return PI*r*r;
}
Sep 26, 2014 at 5:27pm UTC
thanks but im still working on it and it still says there are errors in it
Topic archived. No new replies allowed.