I need a little help trying to figure out why my program is not doing what I need it to do. Here is the program:
#include <iostream.h>
#include <iomanip.h>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int choice1;
float area1, radi1, leng1, heig1, heig2, bas1;
do
{
cout << "The Geometry Calculator" << endl;
cout << endl;
cout << "1. Claculate the area of a circle." << endl;
cout << "2. Claculate the area of a rectangle." << endl;
cout << "3. Calculate the area of a triangle." << endl;
cout << "4. Quit." << endl;
cout << endl;
cout << "Enter your choice (1-4) : " << flush;
cin >> choice1;
if ( choice1 = 1 )
{
cout << "Please enter the radius of the circle: ";
cin >> radi1;
area1 = 3.14159 * ( radi1 * radi1 );
cout << endl;
cout << "The area of the circle with radius " << radi1 << " is " << setprecision ( 4 )
<< setiosflags (ios::fixed | ios::showpoint ) << area1 << endl;
}
else if ( choice1 = 2 )
{
cout << "Please enter the length of the rectangle: ";
cin >> leng1;
cout << "Please enter the height of the rectangle: ";
cin >> heig1;
area1 = leng1 * heig1;
cout << endl;
cout << "The area of your rectangle with length " << leng1 << " and height " << heig1 << " is "
<< setprecision ( 2 ) << setiosflags ( ios::fixed | ios::showpoint ) << area1 << endl;
}
else if ( choice1 = 3 )
{
cout << "Please enter the height of the triangle: ";
cin >> heig2;
cout << "Please enter the base of the triangle: ";
cin >> bas1;
area1 = bas1 * ( 0.5 * heig2 );
cout << endl;
cout << "The area of your triangle with height " << heig2 << " and base " << bas1 << " is "
<< setprecision ( 2 ) << setiosflags ( ios::fixed | ios::showpoint ) << area1 << endl;
}
else if ( choice1 = 4 )
{
cout << endl;
cout << "Thanks for making me think! Please Come Again!!!" << endl;
break;
}
}
while (( choice1 >=1 ) && ( choice1 <= 4 ));
return 0;
}
Now what it is supposed to do is run a continuous loop till option 4 is entered. Everytime I run it, I will only go to option 1 and no other ones. It also makes it tough to escape the loop. What am I doing wrong?