I have to convert this program that I wrote to use switch case statements to handle user input (+, -, /, *, X). Any ideas?
#include <iostream>
#include <string>
using namespace std;
int main()
{
double total = 0, counter = 0;
char sign, X = 0;
double value;
do
{
cout << "Current total is " << total << endl;
cout << "Enter an operation: + - * / (or enter X to exit):";
cin >> sign;
if (sign != 'X')
{
cout << "Enter a number: ";
cin >> value;
cin.ignore();
if (value <= 0)
{
cout << "Can not divide by zero! ";
cout << endl;
}
else
{
if (sign == '+')
{
total += value;
}
else
{
if (sign == '-')
{
total -= value;
}
else
{
if (sign == '*')
{
total *= value;
}
else
{
if ((sign == '/') && (value != 0))
{
total /= value;
}
}
}
}
}
}
}
while (sign != 'X');
return (0);
}