### What am I doing wrong with this program?

I'm trying to teach my self functions by adding them to my already built calculator, but I can't seem to make it work. What am I doing wrong?

#include<iostream>

using namespace std;

int SubNum(int,int);
int MultNum(int,int);
double DiviNum(int,int);
int ModNum(int,int);

int main()
{

int num1, num2, selection;

cout << "Please enter an integer: ";
cin >> num1;

cout << "Please enter another integer: ";
cin >> num2;

cout << "\n\n\n";

cout << "Select the desired function:\n";
cout << "2. Subtraction\n";
cout << "3. Multiplication\n";
cout << "4. Division\n";
cout << "5. Modular Division\n";
cout << "Selection: ";
cin >> selection;

cout << "\n\n\n";

switch(selection)
{

case 1:
cout << "The sum of " << num1 << " and " << num2 << " is " << num1+num2 << endl;
break;
case 2:
SubNum(num1,num2);
cout << "The difference of " << num1 << " and " << num2 << " is " << num1-num2 << endl;
break;
case 3:
MultNum(num1,num2);
cout << "The product of " << num1 << " and " << num2 << " is " << num1*num2 << endl;
break;
case 4:
DiviNum(num1,num2);
cout << "The quotient of " << num1 << " and " << num2 << " is " << num1/num2 << endl;
break;
case 5:
ModNum(num1,num2);
cout << "The remainder of " << num1 << " and " << num2 << " is " << num1%num2 << endl;
break;

default:
cout << "Invalid selection\n";
}
return 0;
}
1st. Please use code formatting (the "<>" button) to post code.

2nd. You haven't actually written the functions, not that you should write a function for adding two numbers together but as an example you need to have something like this:

 ``1234`` ``````int AddNum(int a, int b) { return a+b; }``````

below your code. Then instead of the case 1 that you have you would do.

 ``123`` ``````case 1: cout << "The sum of " << num1 << " and " << num2 << " is " << AddNum(num1, num2) << endl; break;``````

Take a read through this if you are confused still.

http://cplusplus.com/doc/tutorial/functions/
Last edited on
Topic archived. No new replies allowed.