I have a simple calculator in c++ but I also want to add % operation for decimal division. I want to add 5 functions, addition, division, multiplication, subtraction. Everything works but decimal division no. I've got error when I trying to compile. Here is my code:
# include <iostream>
# include <cmath>
# include <cstdio>
using namespace std;
int main()
{
char operation;
float number1, number2;
float fmod;
cout << "Enter operation +, -, *, / : ";
cin >> operation;
cout << "Enter two numbers: ";
cin >> number1 >> number2;
switch(operation)
{
case '+':
cout << number1+number2;
break;
case '-':
cout << number1-number2;
break;
case '*':
cout << number1*number2;
break;
case '/':
cout << number1/number2;
break;
case '%':
cout << number1%number2;
break;
default:
cout << "err";
break;
}
return 0;
}
Can anyone explain how I can add this function?