12-05-2009, 08:04 AM
(12-05-2009, 07:48 AM)MrD. Wrote: You've still used two loops when you could have just used one.2 loops where needed for "Enter your choice" and the menu :\
Code:#include <iostream>
using namespace std;
int main()
{
double a,b;
int option;
cout << ":::Calculator v1::: \n";
cout << "Enter a Number: \n";
cin >> a;
cout << "Enter a Number: \n";
cin >> b;
do {
cout << "1. Multiplication \n";
cout << "2. Division \n";
cout << "3. Addition \n";
cout << "4. Subtraction \n";
cout << "5. Quit \n";
cout << "Enter your choice: ";
cin >> option;
switch (option) {
case 1:
cout << "The Result is: " << a*b << '\n';
break;
case 2:
cout << "The Result is: " << a/b << '\n';
break;
case 3:
cout << "The Result is: " << a+b << '\n';
break;
case 4:
cout << "The Result is: " << a-b << '\n';
break;
case 5:
cout << "Goodbye \n";
break;
default:
cout << "Invalid choice \n";
break;
}
} while(option!=5);
return 0;
}
Also using a double is pointless in this case since std::cout only shows 6 points of precision.
Double is useful in this case for accurate results instead of rounded,I don't get what you mean.