i figured out how to incorporate the switch statements into this program, but i am having trouble making the error term come up if the user tries to divide by zero.
Code:
#include <iostream>
using namespace std;
int main()
{
double n=0, n2=0;
char operation;
cout << "Current Total is " << n << endl;
do
{
cout << "Enter an operation: + - * / (or enter X to exit):" << endl;
cin >> operation;
if (operation == 'X')
break;
cout << "Enter a number: " << endl;
cin >> n2;
switch (operation)
{
case '+':
n += n2;
break;
case '-':
n -= n2;
break;
case '*':
n *= n2;
break;
/* case (('/') && (n2==0)):
cout << "Can not divide by zero!" << endl;
break;
*/
case '/':
n /= n2;
break;
}
cout << "Current Total is " << n << endl;
} while (operation != 'X');
}
the part that is blocked off by the /* and */ is the part i dont know how to figure out. everything else works well with the program, but i dont know how to combine those two like an if statement would be able to do.
thanks for any help.