simple c++ problem

1. Create a file called data.txt with the following data, which are the lengths of the sides of an irregular pentagon in order going clockwise (a, b, c, d, and e). The data file should only contain these five numbers.

45 105 45 90 90

2. Write a C++ program that does the following.


a. Reads the data from the file using 5 separate variable names (e.g. a, b, c, d and e).

b. Assuming the angles between sides a and b as well as b and c are 90 degrees, the program then calculates the remaining three angles of the pentagon.

c. Prints a table to the screen as neatly as possible of the sides and their included angle.


d. In the fourth column of the table, the program prints the word "greater" if the angle is greater than 90 degrees, "less" if the angle is less than 90 degrees and "equal" if the angle is equal to 90 degrees.

Note that the program must be able to run with any data file of five numbers (when a and c are equal and d and e are equal and the angles between a and b and b and c are always 90), not just this set of five. Also, always assume that the pentagon is convex (meaning it points out, not inward).



Here's my code so far:


using namespace std;
#include<iostream>
#include<fstream>
#include<iomanip>
int main()
{
int a1, a2, a3, b1, b2, b3, c1, c2, d1, d2, e1, e2, S1, S2, Angle;
double c3, d3, e3;
char a4, b4, c4, d4, e4, Size ;
ifstream datain ( "data.txt");

S1; S2; Angle; Size;
a1 = 45; a2 = 105; a3 = 90; a4 =0;
b1 = 105; b2 = 45; b3 = 90; b4 =0;
c1 = 45; c2 = 90; c3 = 144.315; c4 =0;
d1 = 90; d2 = 90; d3 = 71.3707; d4 =0;
e1 = 90 ; e2 = 45 ; e3 = 144.315; e4 =0;

cout << "....S1.......S2........Angle..... Size........\n---------------------------------------------------\n";

cout << right;
cout << fixed << setprecision(0) << setw(5) << a1;
cout << setprecision(3) << setw(10) << a2;
cout << setprecision(2) << setw(12) << a3 << endl;
cout << left;

cout<<a4<<"equal"<<endl<<endl;


cout << fixed << setprecision(0) << setw(5) << b1;
cout << setprecision(3) << setw(10) << b2;
cout << setprecision(2) << setw(12) << b3 << endl;
if (Angle==90); {
cout<<Size<<"equal"<<endl<<endl;
}

cout << fixed << setprecision(0) << setw(5) << c1;
cout << setprecision(3) << setw(10) << c2;
cout << setprecision(3) << setw(12) << c3 << endl;
if (Angle>90); {
cout<<"greater"<<Size<<endl<<endl;
}
cout << fixed << setprecision(0) << setw(5) << d1;
cout << setprecision(3) << setw(10) << d2;
cout << setprecision(4) << setw(12) << d3 << endl;
if (Angle<90); {
cout<<Size<<"less"<<endl<<endl;
}
cout << fixed << setprecision(0) << setw(5) << e1;
cout << setprecision(3) << setw(10) << e2;
cout << setprecision(3) << setw(12) << e3 << endl;
if (Angle>90); {
cout<<"greater"<<Size<<endl<<endl;

}


system("pause");
return 0;

}


i am trying to have my equal, greater, and less statements appear under the "Size" column but i have no idea how to do so. Whats wrong with my code?
Thanks
Last edited on
You should not put a semicolon after an if statement, because that reads as: if the condition is true, do nothing and then (always) execute the following block.
Another odd line is:
S1; S2; Angle; Size

It doesn't have any effect. However, your compiler should warn you about this. It should also warn you that Size is never initialized.
Topic archived. No new replies allowed.