Hello all,
I am writing a program that reads in from a file and depending on the first character read in, it will then read in other data and make calculations. The file has data similar to "C 10 or T 10 20" The letter being the shape and the following fields being the parameters...radius, base, height etc. I am hitting a road block when I compile that states a variable is being used without being initialized and I am not sure how to correct this. Ant thoughts?
//Program to determine the area of various shapes
//from given data in input file
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
enum Shapes {ERROR, Triangle, Rectangle, Square, Circle};
istream getInput (istream& input, double base, double height, double width, double radius, double side);
Shapes getShapes (double base, double height, double width, double radius, double side);
int main()
{
char shape, T, t, R, r, S, s, C, c;
double Area;
double base, height, width, radius, side;
ifstream infile ("PJ657_Shapes.txt");
if (!infile)
{
cerr <<"Error: cannot open file\n";
system ("pause");
return 1;
}
ofstream outfile ("PJ657_output.txt");
if (!outfile)
{
cout <<"Error: cannot open PJ657_output.txt";
return 2;
}
infile >> shape;
while (infile)
{
if (shape == T || shape == t)
{
infile >> shape >>base >> height;
Area = .5 * base * height;
outfile <<"The given triangle has an area of "<<Area;
}
else if (shape == R || shape == r){
infile >> shape >> height >> width;
Area = height * width;
outfile <<"The given rectangle has an area of "<<Area;
}
else if (shape == C || shape == c)
{
infile >> shape >> radius;
Area = 3.14*radius*radius;
outfile <<"The given circle has an area of "<<Area;
}
else if (shape == S || shape == s)
{
infile >> shape >> side;
Area = side * side;
outfile <<"The given square has an area of "<<Area;
}
else
outfile <<"Invalid data";
}
system ("pause");
return 0;
}
I don't know if all the code and algorithms are correct or not yet, cant get past this error.