Why Wont My Functions Process The New Values?

Hi all,

So I was given an assignment where I have to input two points (four integers) on a Cartesian plane from a file and then process it using functions. My professor is very particular so the comments are a bit excessive, but here's what I have.

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
  double radiusFn(double, double, double, double);	//4 double values, one for each point. All points are needed for the calculation of distance in this function.
double diameterFn(double);							//Only uses one double value - the radius. Both functions below use the same value.
double circumferenceFn(double);
double areaFn(double);

int main()
{
	cout << "---------------------------------------------------------" << endl;
	cout << "               Circle Statistics Program" << endl;
	cout << "                    David Gambino" << endl;
	cout << "---------------------------------------------------------" << endl;


	ifstream fin;
	fin.open("assignment3data.txt");

	while (fin)
	{

		int x1, x2, y1, y2;
		fin >> x1 >> y1 >> x2 >> y2;
		double radius = sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2));		//Distance formula.
		double points, diameter, circumference, area;

		if (fin)
		{	


			diameter = diameterFn(radius);				//Variable diameter is assigned the value outputted by diameterFn using the value of radius which was just determined.
			circumference = circumferenceFn(radius);	//Variable circumference is assigned the value outputted by circumferenceFn using the value of radius.
			area = areaFn(radius);						//Variable area is assigned the value outputted by areaFn using the value of radius.

			cout << "Statistics for points (" << x1 << ',' << y1 << ") and  (" << x2 << ',' << y2 << ')' << endl;			//implementations proceeding function main.
			cout << fixed << "The radius is: " << setprecision(2) << radius << endl;
			cout << "The diameter is: " << diameter << endl;
			cout << "The circumference is: " << circumference << endl;
			cout << "The area is: " << area << endl << endl;
		}
	}

	fin.close();
}


double diameterFn(double radius)		//Implements calculations to find the diameter of the circle which is simply the radius multiplied by 2.
{
	double diameter = radius * 2;		//Diameter formula.
	return diameter;
}
double circumferenceFn(double radius)				//Implements calculations to find the circumference of the circle.
{
	double circumference = 2 * 3.1416*radius;		//Circumference formula. 3.1416 is pi to the forth decimal place.
	return circumference;
}
double areaFn(double radius)					//Implements calculations to find the circumference of the circle.
{
	double area = 3.1416*pow(radius, 2);		//Area formula.
	return area;
}


The file reads:
1 2 3 4 5 6 7 8 9 10 11 12


It compiles fine, but after the first loop the functions keep return identical statistics, although the outputted values for the x's and y's when I execute the program are changing.

Can anyone tell me how to fix this?
Thanks in advance!
closed account (48T7M4Gy)
line 17 should be while (!fin.eof())

line 25 should be deleted

Note that while/if (fin) is always true, which is not what you mean I guess.
With the input numbers you have, it will always return the same values:

First set of numbers:

x1 = 1, y1 = 2, x2 = 3, y2 = 4

Therefore, in line 22:

radius = sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2))

same as
1
2
radius sqrt(pow((3-1),2) + pow((4 - 2),2);
radius = sqrt(pow((2),2) + pow((2),2)


second set of numbers:

x1 = 5, y1 = 6, x2= 7, y2=8

In line 22:

1
2
radius = sqrt(pow((7 - 5),2) + pow((8 - 6),2));
radius = sqrt(pow((2),2) + pow((2),2)


Not a problem, right? Any four sequential numbers will give identical results.
closed account (48T7M4Gy)
That's a good point about the sequential data. So use something like the following data. Make the program changes. And you'll get some sensible output as follows the data set. ( I haven't checked the arithmetic.
11
2
8
-1
7
6
5
77
9
10
-54
12
---------------------------------------------------------
               Circle Statistics Program
                    David Gambino
---------------------------------------------------------
Statistics for points (11,2) and  (8,-1)
The radius is: 4.24
The diameter is: 8.49
The circumference is: 26.66
The area is: 56.55

Statistics for points (7,6) and  (5,77)
The radius is: 71.03
The diameter is: 142.06
The circumference is: 446.28
The area is: 15849.37

Statistics for points (9,10) and  (-54,12)
The radius is: 63.03
The diameter is: 126.06
The circumference is: 396.04
The area is: 12481.58
Topic archived. No new replies allowed.