You could use a function which generalizes the problem. ie you send the function the sides in the order you want and get back the angle. By using a function you only have to write the equation once.
a function doesn't require a .dat file. You are getting a bit lost I think.
Let's say you want to add up three numbers. You can do it the hard way and write the equation multiple times but if you design a function you can do this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
int functionAdd( int x, int y, int z)
{
return x + y + z;
}
int main()
{
int answer = 0;
answer = functionAdd( 1, 2, 3);
std::cout << answer << std::endl;
answer = functionAdd( 4, 5, 6);
std::cout << answer << std::endl;
}
I should have been more specific in my request for help.
Here is the complete assignment...
I'm just starting, but I think i'm okay on everything except what I asked about the angle function.
Write a complete program to calculate and output the perimeter, the area, the angles of a triangle in degrees, the sum of the three angles in degrees, the radius of the inscribed circle, the radius of the circumscribed circle, and the positive difference in radii using a suitable format to a text file called "triangles.txt" for each calculated value by inputting lower_a, upper_a, step_a, b, c from the data file "triangle.dat" (in Sakai assignment) with a loop for only 'a' which runs from the lower value to the upper value inclusive using the step value (you will test the step to make sure it is positive and make it positive if it isn't - you will output a statement that you are changing the step to make it positive) and an if statement to catch non-triangles (I suggest you look at the area calculation) and output a statement about having a non-triangle for these three sides or output these results for valid ones: perimeter and area with 4 decimal places, all angles with 1 decimal place, and the radii with 5 decimal places using either <iomanip> or <fstream> functions for formatting. In addition, you will have one function to convert radians to degrees, one function to calculate the angle from the sides, and any additional functions to make this program easier to write.
Writing 3 functions to calculate the 3 angles from the 3 sides will cost you ALL credit for this part of the assignment - changing the order of the sides in one function is all that is necessary!
Writing 3 functions to calculate the 3 angles from the 3 sides will cost you ALL credit for this part of the assignment - changing the order of the sides in one function is all that is necessary!
Given what I wrote I wouldn't blame the lecturer for being so tough.
Relating it back to your original function and what wizebin has suggested all you have to do is model that part of the exercise in the same way that functionAdd operates.
I think your use of a,b and c everywhere should be reviewed. Call them x,y and z in the function and then you'll see that a,b, and c can be passed to angleofsides(double x, double y, double z) in any order you need to get the answers returned for the relevant angle you require.
You're on the right track but what I suggest as your first step is just to read the .dat file in and print out the variables instead of jumping in and doing calculations.
Use the demo program from the file input/output tutorial on this site (top left hand menu). The demo includes a while loop to read all the data.
http://www.cplusplus.com/doc/tutorial/files/
This is the starting point which needs to be modified to suit your data structure:
No problem. There's lots more but I'll leave it to you to get back if you get stuck. It takes a little while but better if you try it yourself.
So, lines 10 and 11 are function prototyping, correct?
That's right lines 10 and 11 are the prototypes. You'll notice you don't normally include variable names until you get to the implementation part which normally goes after main() so that once they are working you don't have to wade through them.
You'll get some weird-looking answers ( like 'nan' etc) in some cases and that's because the 3 sides don't make a triangle. Hint: 'triangle inequality' might be a useful term to google.