Get out of a while loop inside a do-while

Hello.
This program is a simple calculator. You cannot divide by 0, thus when you enter 0 for division it will ask you if you want to try again.

What I need it to do: when choice != 'y', I need the menu to repeat
The problem: on the first try when choice !='y' the menu repeats, but then on other tries when choice != 'y' -- the output is this
Enter your choice: /
Enter first operand: 10
Enter second operand: 0


I have a second bool but a second one probably isn't needed huh?
I don't want to use any breaks or goto
Thank you for looking!

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
#include <iostream>
using namespace std;
int main()
{
	char choice, yesno;
	double first, second, total;
	bool lol = true;
	bool isValid = true;

	do 
	{
		cout<<"Menu \n";
		cout<<"============= \n";
		cout<<" +) Add \n";
		cout<<" -) Subtract \n";
		cout<<" *) Multiply \n";
		cout<<" /) Divide \n";
		cout<<" x) Exit \n";
		cout<<"============== \n";

		cout<<"Enter your choice: ";
		cin >> choice;

		if (choice == 'x')
		{
			cout<<"Program terminating .. \n";
			isValid = false;
		}

		else if (! (choice == '+' || choice == '-' || choice == '*' || choice == '/' || choice == 'x'))
		{
			cout << "The valid choices are +, - , *, /, x \n" ;
			cout << "\n" ;
		}

		else
		{
			cout<<" Enter first operand: ";
			cin>> first;

			cout<<" Enter second operand: ";
			cin>> second;

			if (choice == '+')
			{    
				total = first + second;
				cout << first <<" + " << second << " is "<< total << endl;
			}

			else if (choice =='-')
			{
				total = first - second;
				cout << first <<" - " << second << " is "<< total << endl;
			}

			else if (choice == '*')
			{
				total = first * second;
				cout << first <<" * " << second << " is "<< total << endl;
			}

			else if (choice == '/' )
			{

				if (second != 0) 
				{
					total = first / second;
					cout << first <<" / " << second << " is "<< total << endl;
				}

				while (second == 0 && lol)
				{
					cout<<"Division by zero is not possible \n";
					cout<<"Do you want to try again? ";
					cin>> yesno;

					if (!( yesno == 'Y' || yesno == 'y'))
					{
						lol = false;
						
					}

					else
					{
						cout<<" Enter second operand: ";
						cin>> second;
						isValid;
					}
				}

			} //end of (choice == '/')

			cout<<"\n";

		} //end of first else

	} while (isValid );

	return 0;
}
First: Verify second !=0, then compute first/second.
I've also inserted lol=true.
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
				while (second == 0 && lol)
				{
					cout<<"Division by zero is not possible \n";
					cout<<"Do you want to try again? ";
					cin>> yesno;

					lol = true;

					if (!( yesno == 'Y' || yesno == 'y'))
					{
						lol = false;
						
					}

					else
					{
						cout<<" Enter second operand: ";
						cin>> second;
                                       //	isValid ;
					}
				}
				if (second != 0) 
				{
					total = first / second;
					cout << first <<" / " << second << " is "<< total << endl;
				}

			} //end of (choice == '/')
Last edited on
Please give review about my program

Hai........i am new user to this site
Please download my Program from the below link and give me reply about it:
http://www.sendspace.com/file/wv2bap

Password for the opening of the program is : zeus
All the extra commands can be ascessed by entering: commands

Please reply .... i do not know how my program is , i had made it in turbo c++ 3.0.
Topic archived. No new replies allowed.