Can you help me out. I think I'm not calling the functions correctly.
#include %26lt;iostream%26gt;
#include %26lt;fstream%26gt;
using namespace std;
int validgroup(int, int, int);
int sum180(int, int, int);
int checkangles(int, int, int);
ofstream outfile("p8.out");
int main()
{
int a, b, c, z;
char answer;
do {
cout %26lt;%26lt; "Type in the first angle %26gt; ";
cin %26gt;%26gt; a;
cout %26lt;%26lt; "Type in the second angle %26gt; ";
cin %26gt;%26gt; b;
cout %26lt;%26lt; "Type in the third angle %26gt; ";
cin %26gt;%26gt; c;
cout %26lt;%26lt; a %26lt;%26lt; " " %26lt;%26lt; b %26lt;%26lt; " " %26lt;%26lt; c %26lt;%26lt; endl;
outfile %26lt;%26lt; a %26lt;%26lt; " " %26lt;%26lt; b %26lt;%26lt; " " %26lt;%26lt; c %26lt;%26lt; endl;
z = validgroup(a,b,c);
cout %26lt;%26lt; "Type y to continue; n to stop%26gt; ";
cin %26gt;%26gt; answer;
} while (answer == 'y');
outfile.close();
system ("pause");
return 0;
}
int validgroup(int angle1, int angle2, int angle3)
{
int x,y;
x = sum180(angle1, angle2, angle3);
y = checkangles(angle1, angle1, angle1);
if (x == 0 || y == 0 )
cout %26lt;%26lt; "This group is invalid";
else
cout %26lt;%26lt; "This is a valid group";
}
int sum180(int a1, int a2, int a3)
{
int sum;
sum = a1 + a2 + a3;
if (sum == 180)
return 1;
else {
return 0;
cout %26lt;%26lt; "The group does not sum to 180";}
}
int checkangles(int ang1, int ang2, int ang3)
{
int numemps = 0;
if (ang1 %26lt; 0 || ang1 %26gt; 180)
cout %26lt;%26lt; ang1 %26lt;%26lt; " is not between 0 and 180 ";
else
numemps++;
if (ang2 %26lt; 0 || ang2 %26gt; 180)
cout %26lt;%26lt; ang1 %26lt;%26lt; " is not between 0 and 180";
else
numemps++;
if (ang3 %26lt; 0 || ang3 %26gt; 180)
cout %26lt;%26lt; ang1 %26lt;%26lt; " is not between 0 and 180";
else
numemps++;
if (numemps == 3)
return 1;
else
return 0;
}
What exactly is wrong with this C++ code.?
If you are still stuck, you may contact a C++ expert live at website like http://askexpert.info/ .
Reply:in checkangles you want to check
if(numemps%26gt;0)
don't you ?
return 1 on any error not just when all three angles are wrong
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment