0

Whats wrong with my division function void mod() it doesn't work all the others do.

#include <iostream> using namespace std; void add(int a, int b) { int z = a + b; cout << "Sum"" " << z << endl; } /*creates the addition function*/ void subtract(int c, int d) { int f = c - d; cout <<" The result is:" << f << endl; } /*creates the substraction function*/ void times(int x, int y) { int m; m = x * y; cout << "Product:" << m; cout << endl; } /*creates the multiplication function*/ void mod(int e, int v) { int s = e / v; cout << endl; } /*creates the division function*/ int main() { cout << "Calculator" << endl; cout << "Input value_1:" << endl; int q; cin >> q; cout << "Input value_2:" << endl; int o; cin >> o; cout << "Select a mode:" << endl; cout << "1.Addition\n"; cout << "2.Substraction\n"; cout << "3.Multiplication\n"; cout << "4.Division\n"; int w; cin >> w; if (w == 1) { add(q, o); } if (w == 2) { subtract(q, o); } if(w==3){ times(q,o); } if(w==4){ mod(q,o); } return 0; }

15th Aug 2020, 3:10 PM
Michael Baffoe
Michael Baffoe - avatar
1 Respuesta
+ 3
You are not printing anything in mod(), hence there is no output. Other than that, I don't see any errors. Just in case you are expecting a floating-point number as a result when e.g. dividing ten by four: Dividing an integer by another integer will yield an integral result in C++, i.e. the result is stripped of its decimal part. At least one of the operands is required to be a floating-point type to produce a floating-point value as result, in which case it would need to be stored in a variable of type float or double as well.
15th Aug 2020, 3:17 PM
Shadow
Shadow - avatar