Trouble with infinite loop

Can someone help me fix my infinite loop

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

  	cin>> MM_Choice;

	//do
	//{
		switch (MM_Choice)
		{
		case 'A':
		case 'a':
			addition();
			break;
		case'B':
		case'b':
			subtraction();
			break;
		case 'C':
		case 'c':
			multiplication();
			break;
		case 'D':
		case 'd':
			division();
			break;
		case 'Q':
		case 'q':
			quit();
			break;
		default:
			cout << "Please enter a vaild choice" << endl;
			cin >> MM_Choice;
			//continue;

		}//closes switch
	//} while (MM_Choice != 'Q' || MM_Choice != 'q'); 
You need to get new input before the switch statement, because MM_Choice is still whatever you first put into it.
Trouble in multiple condition:
 
    while (MM_Choice != 'Q' || MM_Choice != 'q'); 

Let's say MM_Choice is 'Q'. The first part is false, the second part is true

Let's say MM_Choice is 'A'. The first part is true, the second part is true

The logical OR operator || results in true if either or both operands are true

No matter what the input here, the combined condition is always true.

You need to change the operator to logical AND &&
which will give true only when both operands are true.


Chervil Thank you that worked.
Topic archived. No new replies allowed.