Skip to content

Instantly share code, notes, and snippets.

@WIttyJudge
Created September 30, 2018 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WIttyJudge/af67bd27096496e4203849508db5a147 to your computer and use it in GitHub Desktop.
Save WIttyJudge/af67bd27096496e4203849508db5a147 to your computer and use it in GitHub Desktop.
Features of this programm: 1) Division by zero isn't possible.
#include <iostream>
using namespace std;
int main()
{
float fr, sc, result;
char action1;
cout << " Enter the first number: ";
cin >> fr;
cin.ignore();
cout << "\n" << " To choose one of the action. It can be: \n";
cout << " + (addition), - (subtraction), / (division) or * (multiplication).\n" << " Your choose: ";
cin >> action1;
cout << "\n" << " Enter the second number: ";
cin >> sc;
cin.ignore();
switch (action1)
{
case '+':
{
result = fr + sc;
cout << "\n" << " Result: " << result << endl<<endl;
break;
}
case '-':
{
result = fr - sc;
cout << "\n" << " Result: " << result << endl<<endl;
break;
}
case '*':
{
result = fr * sc;
cout << "\n" << " Result: " << result << endl<<endl;
break;
}
case '/':
{
result = fr / sc;
if (sc == 0)
cout << "\n" << " Error. Devision by zero isn't possible. " << endl<<endl;
else
cout << "\n" << " Result: " << result << endl<<endl;
break;
}
default:
{
cout << "\n" << " Error. Given character wasn't found" << endl<<endl;
}
}
system("pause");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment