Thanks for the reply, Helios
1. Yep you're right - it should have been called something else.
2. Because I didn't only use them in the main () function. I used them also in the "Input" function. What should I have done?
3. I have a basic idea, which I gained from reading a Cambridge C++ tutorial. What I understand is that it is where "
the function is told where in memory the data is stored" (
http://www-h.eng.cam.ac.uk/help/languages/C++/c++_tutorial/functions.html) and this address is stored in pointers x and y.
Why is what I wrote not passing by reference?
4. Haven't I done this?
1 2 3 4
|
cout << "Please input calculation operation (eg. 1 + 2): \n";
cin >> a >> operation >> b;
Input (a,b);
|
Have you any other suggestions? :)
EDIT: Oops I also wanted to add this question, relating to another program:
The following program runs, but stops before displaying "Integer number = ", thereby not allowing the user to input a number. I can't find my mistake... can you help please? Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
// Program to calculate the factorial of a number with a function
#include <iostream>
using namespace std;
// Function Prototype
int Factorial (int M);
int main ()
{
int number=0, result;
// User input must be an integer number between 1 and 10
cout << "Program to calculate the factorial of a number with a function." << endl;
while (number<1 || number>10);
{
cout << "Integer number = ";
cin >> number;
}
// Function call and assignment of return value to result
result = Factorial (number);
cout << "The answer is: " << result << endl;
system ("pause");
return 0;
}
int Factorial (int M)
{
int i, factorial=1;
for (i=1; i<=M; i++)
{
factorial = factorial * i;
}
return factorial;
}
|