Hello
I'm a programming newbie. In fact, this is my second code ever (after the hello world code).
I did a lot of reading actually, here on stack overflow, and other websites, I also purchased "Jumping Into C++" By Alex Allain, And I put Everything I learned here In this code :
Simple Calculator.cpp :
#include <iostream>
#include <string>
using std::cout; using std::cin;
int main()
{
cout << "Calculator..... \n";
cout << "Type '3a3'to exit... \n";
double a=0 ,b=0;
char op = 'a'; //operator // 'a' is the exit operator, the value of the integers doesn't matter
int ch = 0; //while loop checker
do
{
cin >> a >> op >> b;
if (op == '/' && b == 0)
{
cout << "Division By Zero, Please Retry \n" ;
goto retry;
}
switch (op)
{
case '+':
cout << a << " + "<< b << " = " << a+b << "\n";
ch = 0 ;
break;
case '-':
cout << a << " - "<< b << " = " << a-b << "\n";
ch = 0 ;
break;
case 'x':
case '*':
cout << a << " * "<< b << " = " << a*b << "\n";
ch = 0 ;
break;
case '/':
cout << a << " / "<< b << " = " << a/b << "\n";
ch = 0;
break;
case 'a':
ch = 1;
break;
default:
ch = 0;
cout << "Invalid operator, Please retry \n";
}
retry: ;
}while (ch != 1);
}
I would Like To know If there's a way to further improve this code.
Thanks In Advance