Skip to content

Instantly share code, notes, and snippets.

@WIttyJudge
Last active October 1, 2018 12:04
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/c5d841b72e94fcd7e9bd1694819de4ff to your computer and use it in GitHub Desktop.
Save WIttyJudge/c5d841b72e94fcd7e9bd1694819de4ff to your computer and use it in GitHub Desktop.
Feature of this programm: 1) Division by zero isn't possible. 2) You have the opportunity to continue working with the calculator.
#include <iostream>
using namespace std;
float firstNum, secondNum;
char action, returnToAction = 'y';
void addition(float firstNum, float secondNum)
{
cout << " Addition: " << firstNum << "+" << secondNum << "=";
cout << firstNum + secondNum;
}
void subtraction(float firstNum, float secondNum)
{
cout << " Subtraction: " << firstNum << "-" << secondNum << "=";
cout << firstNum - secondNum;
}
void division(float firstNum, float secondNum)
{
cout << " Division: " << firstNum << "/" << secondNum << "=";
if (secondNum == 0)
{
cout << " Division by zero isn't possible";
}
else
{
cout << firstNum / secondNum;
}
}
void multiplication(float firstNum, float secondNum)
{
cout << " Multiplication: " << firstNum << "*" << secondNum << "=";
cout << firstNum + secondNum;
}
int main()
{
while (returnToAction=='y' || returnToAction=='Y')
{
cout << " Enter the first number: ";
cin >> firstNum;
cout << endl;
cout << " What would u like to do with numbers?" << endl;
cout << " U can perforn addition (+), subtraction (-), division(/) or multiplication(*): ";
cin >> action;
cout << " Your choice: " << action;
cout << endl << endl;
cout << " Enter the second number: ";
cin >> secondNum;
switch (action)
{
case '+':addition(firstNum, secondNum); break;
case '-':subtraction(firstNum, secondNum); break;
case '/':division(firstNum, secondNum); break;
case '*':multiplication(firstNum, secondNum); break;
default:
{
cout << " Given character wasn't found";
}
}
cout << endl<<endl;
cout << " Would u like to continue working with calculator?" << endl;
cout << " y/n: ";
cin >> returnToAction;
cout << endl;
}
cout << endl;
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment