fileio problems with fout

Write your question here.
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <cassert>

using namespace std;

double calculateArea(double a, double b, double c);
double calculatePerimeter(double a, double b, double c);
double larger(double a, double b, double c);
double smaller(double a, double b, double c);
double triangle(double a, double b, double c);
void drawLine(ofstream &fout, char ch, int length);
void writeData(ofstream &fout, double a, double b, double c);

int main() {
bool repeat = true;
while (repeat) {
double a, b, c, i;
double larger, smaller;
double area, perimeter, triangle;
ifstream fin;
ifstream fout;

fin.open("sample.in");
if (!fin)
{
cout << "File could not be opened. Exiting program. Make sure files exists!" << endl;
cin.get();
exit(1);
i = 0;
}
fout.open("output.txt");
drawLine(fout, '*', 100);
fout << setw(60) << "Triangle Side length" << endl;
drawLine(fout, '*', 100);
fout << "A= " << setw(10) << "B= " << setw(10)
<< "C= " << setw(10) << "Area= " << setw(10)
<< "Perimeter= " << setw(10) << "Triangle = "
<< "Largest Side= " << setw(10) << "Smallest Side"
<< endl;
drawLine(fout, '=', 100);
i = 0;

if (!fout.is_open())
{
cout << "Output text couldnt be opened to write to." << endl;
exit(0);
}


while (!fin.eof()) {
fin >> a >> b >> c;
fin >> area >> perimeter >> triangle;
writeData(fout, a, b, c);

i++;
}
drawLine(fout, '=', 120);
fout.close();
fin.close();
cout << "Done reading " << i << " records and writing the results " <<
"to output.txt file!" << endl;
cin.get();
return 0;
}
cout << "Would you like to keep going? {y/n]" << endl;
char answer;
cin >> answer;
repeat = answer == 'y';
cout << endl;
void writeData(ofstream &fout, double a, double b, double c) {
area = calculateArea(a, b, c);
area = 0;
perimeter = calculatePerimeter(a, b, c);
perimeter = 0;
max = larger(a, b, c);
max = 0;
min = smaller(a, b, c);
min = 0;
tri = triangle(a, b, c);
cout << fixed;
cout << setpercision(2);
cout << a << setw(10) << b << setw(10)
<< c << setw(10) << Area << setw(10)
<< perimeter << setw(10) << triangle
<< larger << setw(10) << Smallest Side
<< endl;

}
double calculateArea(double a, double b, double c) {
double area = 0.0;
double s = (a + b + c) / 2;
area = sqrt(s(s - a)(s - b)(s - c));
return area;
}
double calculatePerimeter(double a, double b, double c) {
double perimeter = 0.0;
perimeter = (a + b + c);
return perimeter;
}
double larger(double a, double b, double c) {
double max = a;
if (max < b)
max = b;
if (max < c)
max = c;
return max;
}
double smaller(double a, double b, double c) {
double min = a;
if (min > b)
min = b;
if (min > c)
min = c;
return min;
}
void drawLine(ofstream &fout, char ch, int length)
{
fout << setfill(ch);
fout << setw(length) << " " << endl;
fout << setfill(' ');
}
double triangle(double a, double b, double c) {
if (a == b && b == c && c == a) {
cout << "Equilateral\n" << endl;
}
if (a == b || b == c || c == a) {
cout << "Isosceles\n" << endl;
}
else
cout << "Scalene\n" << endl;

return tri;

}
cout << "Have a good day!";
}
What's the problem?
Topic archived. No new replies allowed.