breaking out of a do while loop with a switch nested inside.

This is a small portion of the code i am working on. I am try to figure how i can exit this loop when asked to do so. But i have to allow the user to make multiple changes until the user tells the program to exit. i have every thing else figured out in the program but one part.

this is also inside an if statement.
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
cout << "Would you like to deposit or withdrawal funds: " << endl;
	  cout << "D or d (Deposit), W or w (withdrawal),  E or e (exit) :" << endl;                 
    	cin >>  DorW;                           
    	cout << endl;
    	
    	do
    	{
    	switch (DorW)
    	{
	     case 'd':
	     case 'D':
	      cout << "How much to deposit: $" << endl;
	      cin >> total;
	      cbalance = cbalance + total;
	     	break;
	     case 'w':
	     case 'W':
	       cout << "How much to withdrawl: $" << endl;
	       cin >> total;
	       cbalance = cbalance - total;
	       if (cbalance >= 0)
	       	{cout << "Sucessfully withdrawn" << endl;}
	       	else
	       	{ cout << "Insufficient funds - the withdrawal is being denied." << endl;
	       	cbalance = cbalance + total;}
	       	break;
	       case 'e':
	       case 'E':
	       DorW = 'e';
	       	break;
	     default: 
        cout << "Invalid selection type." << endl;
        	break;
    	}
    	cout << "Would you like to deposit or withdrawal funds: " << endl;
	      cout << "D or d (Deposit), W or w (withdrawal),  E or e (exit) :" << endl;                 
    		cin >>  DorW;                           
    		cout << endl; 
		}while(DorW != 'e' || DorW != 'E');	
		}
no shore if this is what you wanted:

1
2
3
4
5
6
do {
    switch(...) {
     //....
    }
    if(some_condition) break;
}while(true);
that is not quite it unless i am miss understanding the use of the example you provided.

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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
int main() 
{ 
 
int acct;
char DorW, acctt;
double minbalance, cbalance, balance, total;
ifstream indata;
ofstream outdata;



indata.open("bank.dat");

indata >> acct;
while(!indata.eof())
{
indata >> acctt >> minbalance >> cbalance;
cout << fixed << setprecision(2) << showpoint;

if (acctt == 's' || acctt == 'S')
	{ cout << "Would you like to deposit or withdrawal funds: " << endl;
	  cout << "D or d (Deposit), W or w (withdrawal),  E or e (exit) :" << endl;                 
    	cin >>  DorW;                           
    	cout << endl;
    	
    	do
    	{
    	switch (DorW)
    	{
	     case 'd':
	     case 'D':
	      cout << "How much to deposit: $" << endl;
	      cin >> total;
	      cbalance = cbalance + total;
	     	break;
	     case 'w':
	     case 'W':
	       cout << "How much to withdrawl: $" << endl;
	       cin >> total;
	       cbalance = cbalance - total;
	       if (cbalance >= 0)
	       	{cout << "Sucessfully withdrawn" << endl;}
	       	else
	       	{ cout << "Insufficient funds - the withdrawal is being denied." << endl;
	       	cbalance = cbalance + total;}
	       	break;
	       case 'e':
	       case 'E':
	       DorW = 'e';
	       	break;
	     default: 
        cout << "Invalid selection type." << endl;
        	break;
    	}
    	if(DorW != 'e' || DorW != 'E') break;
    	cout << "Would you like to deposit or withdrawal funds: " << endl;
	      cout << "D or d (Deposit), W or w (withdrawal),  E or e (exit) :" << endl;                 
    		cin >>  DorW;                           
    		cout << endl; 
    	
		}while(true);	
		}
else
	{cout << "Would you like to deposit or withdrawal funds: " << endl;
	  cout << "D or d (Deposit), W or w (withdrawal),  E or e (exit) :" << endl;                 
    	cin >>  DorW;                           
    	cout << endl;
    	do {
    	switch (DorW)
    	{
	     case 'd':
	     case 'D':
	      cout << "How much to deposit: $" <<endl;
	      cin >> total;
	      cbalance = cbalance + total;
	     	break;
	     case 'w':
	     case 'W':
	       cout << "How much to withdrawl: $" << endl;
	       cin >> total;
	       cbalance = cbalance - total;
	       if (cbalance >= 0)
	       	{cout << "Sucessfully withdrawn" << endl;}
	       	else
	       	{ cout << "Insufficient funds - the withdrawal is being denied." << endl;
	       	cbalance = cbalance + total;}
	       	break;
	       case 'e':
	       case 'E':
	       	break;
	     default: 
        cout << "Invalid selection type." << endl;
    	} cout << "Would you like to deposit or withdrawal funds: " << endl;
	      cout << "D or d (Deposit), W or w (withdrawal),  E or e (exit) :" << endl;                 
    		cin >> DorW;                           
    		cout << endl;
		}while (DorW != 'e' || DorW != 'E');
      
 }
 outdata << acct << " " << acctt << " " << minbalance << " " << balance << endl;
 indata>>acct;
}


return 0; 
}


i have a .dat file that i am getting the information from. their are some calculations left out that i will be incorporating. I have compiled the program and it shows no errors, but for some reason it just keeps asking the quest no matter how many times i enter 'e' for exit. What i need to do is exit the do loop the and continue one with the program. I know the outdata portion is not right i will deal with after i get this problem resolved.
Topic archived. No new replies allowed.