Hi guys, I am having a bit of trouble. I've come to realize that my book does a poor job to explain a lot of concepts in detail.
I am trying to use functions in the folowing code.
#include <iostream> //For cin and cout
using namespace std;
int main(void)
{
int number1, //INPUT
number2;
cout << "Enter first number: " << endl;
cin >> number1;
cout << "Enter second number: " << endl;
cin >> number2;
int sum, //CALCULATIONS
difference,
product,
quotient;
sum = number1 + number2;
difference = number1 - number2;
product = number1 * number2;
quotient = number1 / number2;
cout << "\n\nNumber 1: " << number1 << endl //OUTPUT
<< "Number 2: " << number2 << endl
<< "\n\nAnswers: "
<< "\n sum = " << sum
<< "\n difference = " << difference
<< "\n product = " << product
<< "\n quotient = " << quotient << "\n" << endl;
cout << "Press any key to exit." << endl;
cin.ignore(2);
return 0;
}
What i wanna do, is to have a function say, for the menu.
I know i have to list the function and the bottom of the code, outside the bracket.
But, how do you call it? I don't undesrtand the parameters as well.
Basically, instead of having the whole menu up there, I wanna have a function like "getmenu ()" to display the menu.
I realize that it is the same (with more work), but I'm trying to understand this here because as homework, I will be using functions for calculations.
I know that the variables stated and out put would stay within the body.
But the equations?
If I understand, you would use this part for the function,
int sum, //CALCULATIONS
difference,
product,
quotient;
sum = number1 + number2;
difference = number1 - number2;
product = number1 * number2;
quotient = number1 / number2;
correct?
how would you make the calculations in this example a function?