Oct 5, 2011 at 3:15am UTC
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 Oct 5, 2011 at 3:18am UTC
Oct 5, 2011 at 3:34am UTC
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)
Oct 5, 2011 at 3:44am UTC
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?
Oct 5, 2011 at 3:56am UTC
So do you just want an infinite loop?
Oct 5, 2011 at 3:57am UTC
just about, until the user punches in 'q' and then they're let out
Oct 5, 2011 at 4:11am UTC
Yep, that pretty much solved it, would have never thought to use bool.
Thanks Meerkat!