Hey all! I'm new to C++ and am having trouble with the Do...While loop terminating. My problem is I want the loop to end when the user enters 'X' when asked for an operation. When 'X' is entered it still asks for a number and then displays the current total before ending. Is there any way to get the program to end immediately after the user enters 'X'? I understand I can use an If statement and break the loop when operation == 'X' but I feel like this would defeat the purpose of using a Do....While loop.
#include <iostream>
using namespace std;
int main()
{
double start = 0, number;
char operation;
cout << "Current total is " << start << endl;
do
{
cout << "Enter an operation: + - * / (or enter X to exit):";
cin >> operation;
cout << "Enter a number: ";
cin >> number;
if (operation == '+')
start = start + number;
else if (operation == '-')
start = start - number;
else if (operation == '*')
start = start * number;
else if ((operation == '/') && (number == 0))
cout << "can not divide by zero!" << endl;
else if (operation == '/')
start = start / number;
cout << "Current total is " << start << endl;
} while (operation != 'X');
}