Cant figure out how to complete a condition

Hey guys, I have this program thats almost done, but there's one final condition i need to complete before I can run it.
Specifically, im drawing a total blank with lines 5 and 48.
Can someone give a crack at this?

Thanks in advance

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

int main(){
	double // fill in what's missing here.
	char choice;
	
	do {
		cout << "***** Simple Calculator *****" << endl;
		cout << "  Pick an operation: " << endl;
		cout << "  + to do addition." << endl;
		cout << "  - to do subtraction." << endl;
		cout << "  * to do multiplication." << endl;
		cout << "  / to do division." << endl;
		cout << "  2 to square a number." << endl;
		cout << "  q to quit." << endl;
		cin >> choice;
		
		if (choice == '+' || choice == '-' || choice == '*' || choice == '/') {
			cout << "Enter two numbers: ";
			cin >> num1 >> num2;
			if (choice == '+') {
				result = num1 + num2;
			}
			
			if (choice == '-') {
				result = num1 - num2
			}

			if (choice == '*') {
				result = num1 * num2
			}

			if (choice == '/') {
				result num1 / num2
			}			
			
		}

		if (choice = '2') {
			cout << "Enter a number: ";
			cin >> num1;
			result = num1 * num1;
		}
		if (choice != 'q'){
			cout << num1 << choice << num2 << " = " << result << endl;
		}
	}while ( /* complete this condition */ );
	cout << "Press a key then enter. ";
	cin >> choice;

	return 0;
}
Last edited on
What do you want the while loop to do? Just keep looping until the person presses q?

Also you need to declare result, num1, num2 as doubles (or floats)
I want the loop to take me back to the calculator portion, Im just not too sure how it is that I take it back to that part. how would I go about that?
So do you just want an infinite loop?
just about, until the user punches in 'q' and then they're let out
ah right. so it is what I originally thought.

change double // fill in what's missing here.
to bool exit = false;


and change }while ( /* complete this condition */ );
to }while ( exit ==false );


change
1
2
3
if (choice != 'q'){
			cout << num1 << choice << num2 << " = " << result << endl;
		}

to
1
2
3
4
if (choice != 'q'){
			cout << num1 << choice << num2 << " = " << result << endl;
                        exit = true;
		}


I hope that should work.
You still have other problems with you code, let me know if you can't figure them out.
Yep, that pretty much solved it, would have never thought to use bool.
Thanks Meerkat!
Topic archived. No new replies allowed.