Skip to content
Snippets Groups Projects
Commit 8f68e61a authored by Rudi Buss's avatar Rudi Buss
Browse files

Update Solution Exercise 4 - Calculator.cpp

parent cb66bab6
No related branches found
No related tags found
No related merge requests found
#include <iostream>
using namespace std ;
using namespace std;
int main ()
{
float z1, z2, result;
char op;
cout << "2 numbers with operator in between [+ - * / ]: ";
cin >> z1 >> op >> z2 ;
cout << z1 << op << z2 << "=";
switch (op)
{
case '+':
result = z1 + z2;
cout << result << endl;
break ;
case '-':
cout << z1 - z2 << endl;
break ;
case '*':
cout << z1 * z2 << endl;
break ;
case '/':
if ( z2 ==0)
cout << " Division by 0 is not possible" << endl;
else
cout << z1 / z2 << endl;
break ;
default :
cout << " I do not know this operator." << endl;
}
return 0;
int main() {
float z1, z2, result;
char op;
cout << "2 numbers with operator in between [+ - * / ]: ";
cin >> z1 >> op >> z2;
cout << z1 << op << z2 << "=";
switch (op) {
case '+':
result = z1 + z2;
cout << result << endl;
break;
case '-':
cout << z1 - z2 << endl;
break;
case '*':
cout << z1 * z2 << endl;
break;
case '/':
if (z2 == 0)
cout << " Division by 0 is not possible" << endl;
else
cout << z1 / z2 << endl;
break;
default:
cout << " I do not know this operator." << endl;
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment