Error message pops up, working with functions and external files

I'm working on a program that will read an undetermined number of real number triplets from an external data file. The triplets represent 3 possible sides of a triangle. I'm trying to write a program that will determine if the sides do in fact form a triangle, that calculates the perimeter to 3 decimal places and that calculates the area of the triangle using Heron's formula.

The output is supposed to be in tabular form like:

Sides Triangle? Perimeter Area
1.000 2.000 3.000 False

My code looks like it should work (to my C++ beginner eyes). BUT when I go to debug and compile the code, I get an error message that pops us that says: Unable to start program. The system cannot find the file specified.

I'm not sure what this means, or what I could do to fix this. Any help would be appreciated. I'm posting the code here in case that the error message is a function of my code.

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
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdlib>
using namespace std;

bool isatriangle(double side1, double side2, double side3);
//Determine if the sides do form a triange, the sum of any two sides must be greater than the third side.

double semiperimeter(double side1, double side2, double side3);

double triperimeter(double side1, double side2, double side3);
//Calculate the perimeter.

double triarea(double side1, double side2, double side3);
//Calculate the area of a triange, using Heron's formula.


int main()
{
	double area, perimeter, semiperimeter, side1, side2, side3;
	bool isatriangle(double side1, double side2, double side3);


	ifstream infile("c:\ExternalFiles\exfileTriangleSides.txt");
	if (!infile) {
		cerr << "Input file could not be opened" << endl;
		exit(1);
	}
	ofstream outfile("c:\ExternalFiles\exfileTriOut.txt");
	if (!outfile){
		cerr << "Output file could not be opened" << endl;
		exit(1); 
	}

	infile >> side1 >> side2 >> side3;

	//Create table

	outfile << "\t\t\t Sides \t\t\t Triangle? \t\t\t Perimeter \t\t\t Area" << endl;


	while (infile >> side1 >> side2 >> side3)
	{
		outfile << "\t\t\t Sides \t\t\t Triangle? \t\t\t Perimeter \t\t\tArea" << endl;
		outfile << fixed << setprecision(4) << side1 << side2 << side3 << "\t\t\t" << isatriangle << "\t\t\t" << triperimeter << "\t\t\t" << triarea << endl;
	}
	
	infile.close();
	outfile.close();

	system("pause");
	return 0;
}


bool isatriangle(double side1, double side2, double side3)
{
	if (side1 + side2 >= side3 && side1 + side3 >= side2 && side2 + side3 >= side1)
		cout << "True" ;
	else
		cout << "False" ;
}

double triperimeter(double side1, double side2, double side3)
{
	double perimeter,

	perimeter = side1 + side2 + side3;
	cout << fixed << setprecision(3) << perimeter << endl;
}

double semiperimeter(double side1, double side2, double side3)
{
	double s;

	s = (side1 + side2 + side3) / 2.0;
	cout << fixed << setprecision(3) << s << endl;

}

double triarea(double side1, double side2, double side3)
{
	double area;

	area = sqrt(semiperimeter(side1, side2, side3) * (semiperimeter(side1, side2, side3) - side1) * (semiperimeter(side1, side2, side3) - side2) * (semiperimeter(side1, side2, side3) - side3));
	cout << fixed << setprecision(3) << area << endl;
}
Your IDE probably can't find the executable file because your program failed to compile.

Line 26,31: \ characters need to be escaped. i.e. \\

Line 68: Should end with a ; not a ,




Thanks AbstractionAnon!

That worked and my file is compiling. I'm not getting the right outputs so I have to do some more fine-tuning, but at least I can see what it looks like!

Topic archived. No new replies allowed.