trouble with else-if statement

When I execute the code below, it will execute which ever option you enter once. It will ask for another option as it is supposed to, but when you enter the second time, it ends the program. I have been trying to see in the book where I am going wrong, but not seeing it. Any help would be greatly appreciated. Thanks

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
#include <iostream>
using namespace std;

int main( )
{  
int menu(), option;
double meters, feet, meters_length, meters_width, feet_length, feet_width, area;

do 
{
   option = menu();
      if (option == 1)
       {
         cout << "How many meters?";
         cin >> meters;
         feet = meters * 3.28084;
         cout << meters;
         cout << " meters are equivalent to ";
         cout << feet;
         cout << " feet.\n";
         option = menu();
         }
      else if (option == 2)
      {
         cout << "How many feet?";
         cin >> feet;
         meters = feet * 0.3048;
         cout << feet;
         cout << " feet is equivalent to ";
         cout << meters;
         cout << " meters.\n";
         option = menu();
         }
      else if (option == 3)
      {
         cout << "What is the length of the rectangle in meters?";
         cin >> meters_length;
         cout << "What is the width of the rectangle in meters?";
         cin >> meters_width;
         feet_length = meters_length * 3.28084;
         feet_width = meters_width * 3.28084;
         area = feet_length * feet_width;
         cout << "The area of the rectangle is ";
         cout << area;
         cout << " square feet.";
         option = menu();
         }
      else if (option == 4)
      {
         cout << "What is the length of the rectangle in feet?";
         cin >> feet_length;
         cout << "What is the width of the rectangle in feet?";
         cin >> feet_width;
         meters_length = feet_length * 0.3048;
         meters_width = feet_width * 0.3048;
         area = meters_length * meters_width;
         cout << "The area of the rectangle is ";
         cout << area;
         cout << " square meters.";
         option = menu();
         }

} while (option =! 5);   

return 0;

}

menu()
{
int option;

cout << "English-Metric Junoir\n";
cout << "   1) Convert from meters to feet\n";
cout << "   2) Convert feet to meters\n";
cout << "   3) Compute the area of a rectangle in square feet given the length and width in meters\n";
cout << "   4) Compute the area of a rectangle in square meters given the length and width in feet\n";
cout << "   5) Quit the program\n";
cout << "Please enter number (1-5) ->";
cin >> option;

while ((option < 1) || (option > 5))
   {
   cout << "Not a valid option. Please enter a number 1-5.";
   cin >> option;
   }
return option;
}
1
2
3
4
5
6
7
8
(option =! 5)
// is same as
( option = ! 5 )
// is same as
( option = (! 5) )
// Since you won't care about the assigned value of option,
you effectively test
( ! 5 )

You do have logical not and an assignment.

Try the (option != 5)
The != is a relational operator.
Topic archived. No new replies allowed.