File input and modules

I'm doing another project for school, and I'm struggling a little with a few glitches I'm having. What happens is the program asks for an input file name, and then draws numbers from that file to use to calculate the different sides of triangles. It uses modules for the calculations, and once it goes through all the modules, it grabs the next three numbers from the file.

My program goes through the first set of numbers okay, except for a few calculation bumps, but then on the second and third sets it changes the last number to 13 instead of 3, and repeats the third set of numbers entirely. I don't even know which batch of code I should be checking, and there's 139 lines of it. Does anyone have any suggestions at least for where to start?
Start at line 120.

Seriously though, something that comes to mind (besides the need for sharing some code or smth) is that you may be using loop that checks for eof at the start and reads stuff inside the body. There may be a problem with this, but only if you are reading fixed portions from a binary file.

Share some intellectual property :)

Regards
I have no problem sharing, I just didn't know what the rules were when it came to so much.

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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>

using namespace std;

bool isTriangle (double num1, double num2, double num3)
{
   int case1, case2, case3;
   case1=num1+num2;
   case2=num2+num3;
   case3=num1+num3;
   if (case1>num3&&case2>num1&&case3>num2)
      return true;
   else 
      return false;
}
  
bool isRight(double sideA, double sideB, double sideC)
{
   double AA, BB, CC, AB, AC, BC;
   AA=sideA*sideA;
   BB=sideB*sideB;
   CC=sideB*sideB;
   AB=AA+BB;
   AC=AA+CC;
   BC=BB+CC;
   if (AB==CC||BC==AA||AC==BB)
      return true; 
   else
      return false;
}

bool isEquilateral (double sideA, double sideB, double sideC)
{
   if (sideA==sideB&&sideB==sideC)
      return true;
   else
      return false;
}

bool isIsosceles (double sideA, double sideB, double sideC)
{
   if (sideA==sideB||sideA==sideC||sideB==sideC)
      return true;
   else
      return false;
}

bool isScalene (double sideA, double sideB, double sideC)
{
   if (sideA!=sideB&&sideA!=sideC&&sideB!=sideC)
      return true;
   else
      return false;
}

void calcTriangle (double sideA, double sideB, double sideC, double& perimeter, double& area)
{
   perimeter=sideA+sideB+sideC;
   int S=perimeter/2;
   int SA, SB, SC;
   SA=S-sideA;
   SB=S-sideB;
   SC=S-sideC;
   area=sqrt(S*SA*SB*SC);
}

int main()
{
   fstream inFile;
   string inFileName;
   double num1, num2, num3;

   cout<<"Enter the name of the data file> ";
   cin>>inFileName;
   cout<<endl;
   inFile.open(inFileName.c_str(),ios::in);
   if (inFile.fail())
   {
      cout<<"Unable to open "<<inFileName<<endl;
      exit(1);
   }
   cout<<"     Triangle Program Report     "<<endl<<setw(32)<<setfill('=')<<right<<" "<<endl;
   while (!inFile.eof())
   {
      inFile>>N1>>N2>>N3;
      if (isTriangle (num1, num2, num3))
      {
         cout<<"The sides of the triangle are:"<<endl;
         cout<<"A  =  "<<setprecision(2)<<num1<<";    "<<"B  =  ";
		 cout<<setprecision(2)<<num2<<";    "<<"C  =  "<<setprecision(2)<<num3;
         cout<<endl<<endl;

         double peri, are;
         calcTriangle (num1, num2, num3, peri, are);
         cout<<setw(10)<<setfill(' ')<<left<<"Perimeter"<<"= ";
		 cout<<setprecision(4)<<fixed<<setw(8)<<right<<peri<<endl;
         cout<<setw(10)<<left<<"Area"<<"= ";
		 cout<<setprecision(4)<<fixed<<setw(8)<<right<<are<<endl<<endl;

         cout<<"Classification:"<<endl;
         cout<<setw(13)<<left<<"Right:";
         if (isRight(num1, num2, num3))
            cout<<"Y"<<endl;
         else
            cout<<"N"<<endl;

         cout<<setw(13)<<setfill(' ')<<left<<"Isosceles:";
         if (isIsosceles(num1, num2, num3))
            cout<<"Y"<<endl;
         else
            cout<<"N"<<endl;

         cout<<setw(13)<<setfill(' ')<<left<<"Scalene:";
         if (isScalene(num1, num2, num3))
            cout<<"Y"<<endl;
         else
            cout<<"N"<<endl;

         cout<<setw(13)<<setfill(' ')<<left<<"Equilateral:";
         if (isEquilateral(num1, num2, num3))
            cout<<"Y"<<endl;
         else
            cout<<"N"<<endl;
      }
      else
      {
         cout<<"***  "<<fixed<<setprecision(2)<<num1<<", "<<setprecision(2)<<num2<<", and "<<setprecision<<num3;
         cout<<" cannot form the sides of a triangle  ***"<<endl;
      }
      cout<<setw(32)<<right<<setfill('-')<<" "<<endl;
   }
   cout<<setw(9)<<setfill(' ')<<left<<"***"<<"END OF REPORT"<<right<<setw(9)<<"***"<<endl;
   cout<<setw(33)<<setfill('=')<<endl;
   return 0;
}


Like I said, there's a few calculation blips in at least the right triangle module, but I'm mostly worried about the reading aspect. Thank you so much for your help.
The overall structure seems ok.
One thing that I can propose is that you test if the data is inputted successfully every time. This may be necessary for example if the last line in the input file is empty, in which case you will not get eof, but the next read will fail.

You can test like that:
if(inFile>>N1>>N2>>N3) {/*success*/} else {/*failure*/}

Other than that, you've got things mixed on line 26, and I think you should use type double on lines 63 and 64.

I don't understand the 3 -> 13 substitution that you mentioned. If none of the above corrects it, please post the input file, so that I can debug it on my PC.

Btw, I was seriously joking. And you are right, people sometimes dump a lot of code here with no explanation of their problem, which is indeed irritating. But then again, sometimes a person can have legit reason not to want to post their code. You can still get help, but it is harder.

Regards
Oh, I didn't take any offense, man. =) Sorry if I seemed bitchy, I was exhausted last night and too tired to even care about the right triangle module. I can't believe I missed something as simple as that, though...
I do have the line of code that says it couldn't load the file and closes the program. Dos that count as what you mean by the success and fail bit? If not, do I just enter the text I want to be displayed in cout in the brackets for that line you gave me?
Okay, the line repeating was due to an extra space in the input file. My text editor refused to leave it off, so I ended up opening it in a different editor. -.-
I got the blip in the isRight module figured out, and everything seems to be running correctly except for when it ISN'T a triangle. Then it outputs the line like it's supposed to, up until the last number. It's not 13 necessarily, it's adding 10 to that number. But whatever the error is, it should only be in either isTriangle or in the last few lines where I say what to do if it isn't a triangle, right?
Well, one small modification is to substitute line 87, which is currently
while (!inFile.eof())
with
while (inFile>>N1>>N2>>N3).

I advised you to use if-else conditional, because you can put it inside the loop, and not only break the loop, but also emit some message. But you could try the substitution above and see if it works.
Topic archived. No new replies allowed.